47 Commits
Author SHA1 Message Date
Thomas MartinandClaude Opus 5.5 37abf45ccb libsd: an effect work area clear takes its SPU2 DMA time, also for ready-completion hosts
sceSdCleanEffectWorkArea reported its end after the transfer latency alone,
and a host that delivers audio completions at once (VP2S) ran it immediately.
VP2's reverb change (Csm export 8) clears core 0, then core 1, then releases
its lock; the EE asks (Csi RPC 0x1c) about two frames later whether the change
is still running and sends it again when it is not. With a clear that takes no
time it was never running: the castle-hall event of chapter 2 waited forever.

The clear's end now comes after the area's DMA time (16 IOP cycles per
halfword: mode 7 is 0x18040 bytes, about 21 ms per core) through a new
LibsdHost::interruptCallAfterWork, which ready-completion hosts honour (its
default forwards to interruptCall). Test: the end's delay and its route.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 14:29:51 +01:00
boubou666 f3bc935052 Merge pull request #173 from TheBozos/claude/sysclib-word-routines
Native IRX: sysclib strstr (34), wmemcopy (40) and wmemset (41)
2026-11-30 23:05:04 +01:00
Thomas MartinandClaude Opus 5.5 a3d27ce9d5 Native IOP threads: a deleted thread's stack is taken again
CreateThread took each task's stack from a bump arena (0x1fe000 down to 0x190000) and DeleteThread never gave it
back, so a game that creates and deletes IOP threads at every map load ran the arena out: Steambot Chronicles stopped
with "native library task stacks exhausted" (thbase 4) after about 20 map loads.

- DeleteThread puts the task's stack on a free list; CreateThread takes the smallest free stack that fits (its whole
  size becomes the task's) before the arena's next.
- The free list is saved in the IOP section's new "taskstacks" part; a state saved before it loads with none free.
- Test: 257 CreateThread / DeleteThread pairs with 4 KiB stacks, each thread on the first one's stack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 14:38:39 +01:00
Thomas MartinandClaude Opus 5.5 6f78a775f3 Native IRX: sysclib strstr (34), wmemcopy (40) and wmemset (41)
Capcom's SNDDRV.IRX 2.27W (Breath of Fire: Dragon Quarter) parses its arguments
with strstr and moves and clears its stream buffers with wmemcopy / wmemset
(bytes / 4 words). Test: tests/native/library_sysclib_words_tests.cpp.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 10:19:16 +01:00
Thomas MartinandClaude Opus 5.5 24691830b2 Native IRX: a work-free IOP clock (opt-in) and an import call log (BOZO_IRX_CALLS)
CompiledLibraries::useWorkFreeClock(): the IOP clock moves only with its own
events (deadlines, timers, the EE's time), not with the work compiled code
does, so a native rewrite of a compiled routine meets the same times and a
timer handler's work no longer delays its next period.

BOZO_IRX_CALLS=<file>: every import call (cycle, library, ordinal, a0-a3,
the caller, the result) written out, to compare two runs of the same
modules, compiled or rewritten. docs/native-irx.md also describes bindings
that sleep and resume at admitted return addresses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 19:16:40 +01:00
Thomas MartinandClaude Opus 5.5 847b6a49c8 native IRX cdvdman: the stream (sceCdStInit, StStart, StRead, StSeek, StStat, StStop)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 12:39:20 +01:00
Thomas MartinandClaude Opus 5.5 eb05b04ca0 SPU2 output IRQ: the mix stops at it, its handler 32 samples on
A sample-clocked timer on the output write-back (Harmonix's softFX refills
core 0's input area on it) was answered only after the whole mix of a
frame, so its refills landed anywhere in the half being played: stale
halves replayed, a crackle and a slowed-down sound. The native IRX host's
mix now stops where the output reaches an enabled IRQ address
(Mixer::nextOutputIrqCycle), and the SPU2 interrupt's handler runs 32
samples later (Libsd::kIrqResponse): the IOP's response and its driver's
work, which take no time here. Run at once, softFX's transfer landed 2
samples before the half it refills had played.

Amplitude's tutorial narration: 265 clicks in 65 s before, 7 after; the
song select's previews likewise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 19:16:51 +01:00
Thomas MartinandClaude Opus 5.5 ef902f605a libmpeg: the SDK's demux (sdkDemux), picturesAhead; PAL console; block transfer status ahead
- MpegOptions::picturesAhead (was kPicturesAhead, 8): how far the demux reads ahead of the game. Shinobido's first
  audio packet comes 14 pictures into the stream and its player waits for 0x6000 bytes of it.
- MpegOptions::sdkDemux: sceMpegDemuxPssRing as the SDK runs it. Each packet's callback runs before the demux goes
  on (the calling thread waits for it), and a 0 from the sound callback ends the call before that packet, which the
  next call gives again; only whole packets are taken. Shinobido's PCM callback refuses a packet when its ring is
  full: with the queued callbacks a refused packet was lost, and the sound after an odd-sized one (4073 bytes) was
  read a byte off (noise from 28 s into its intro). A video callback's 0 is not waited for: the decoder takes the
  video from the demux and the game's own IPU input is never drained. Off by default (TMB unchanged).
- Libraries::palConsole: sceGsResetGraph's video mode 0 (the console's own standard) at 50 Hz on a PAL console.
- CompiledLibraries::useBlockTransStatusAhead: sceSdBlockTransStatus one 1 KB block ahead of the sample playing, as
  the SPU2's input DMA reports it (a driver keeping its ring full by it). Off by default (TMB's logged answers kept).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 18:30:07 +01:00
Thomas MartinandClaude Opus 5.5 3b7973008b Native SPU2 interrupt; IOP sceSifCheckStatRpc and sceSifSetDChain
- Mixer: a core's IRQ address and enable (setIrqAddress / setIrqEnabled).
  A voice reading the 16-byte block that holds the address (a block
  decoded, a key on) or a transfer writing over it calls the IRQ
  callback once. The core then stays disabled until it is enabled again,
  as the SPU2's IRQ flag is cleared. Both are saved with the mixer's
  state.
- libsd: SD_A_IRQA (0x1F00) and SD_CORE_IRQ_ENABLE (0x4) drive the mixer.
  sceSdSetSpu2IntrHandler (27) keeps its handler, which the interrupt
  calls as handler(1 << core, argument) through the host's interrupt
  calls, like the transfer handlers. It was a no-op before.
- IRX host: sifcmd 18 (sceSifCheckStatRpc) answers 0, since IOP calls to
  EE services complete within sceSifCallRpc. sifman 6 (sceSifSetDChain)
  does nothing, as no chain mode needs arming.

Capcom's SNDDRVCD (Onimusha: Warlords) plays its voice streams (ADS)
through the SPU2 interrupt and reports a stream busy until it ends. Its
room events wait for that, so the first room's opening never started.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 16:31:28 +01:00
Thomas MartinandClaude Opus 5.5 575db8fdce Native IRX host: sysclib memmove and strrchr; libsd VOLX follows the envelope
- compiled_libraries: sysclib 13 (memmove) shares memcpy's overlap-safe copy;
  sysclib 32 (strrchr) returns the last occurrence or 0. Capcom's SNDDRVCD
  (Onimusha: Warlords) imports both.
- libsd: VOLXL / VOLXR report the voice's current volume (its volume scaled
  by ENVX, a sweeping volume counting as full), as the SPU2 does, instead of
  the volume as set. SNDDRVCD releases a voice and polls VOLX until it
  reaches 0; with the set volume it never did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 15:29:29 +01:00
Thomas MartinandClaude Opus 5.5 b6dc6cd44f Merge JC2's save states (jc2/native-irx-host b73692e) into TTA's integration
Conflicts: libmpeg's Nodata end becomes a Resume record that keeps TTA's SDK callback (a[2] flags:
1 work area, 2 SDK callback; 0 is the reference's behaviour); cdvdman keeps JC2's drive commands and
TTA's sceCdSearchFile. TTA's state the archive did not have: libpad2's sockets, the IOP software
registers and libmpeg's inputEnded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 18:30:24 +01:00
Thomas MartinandClaude Opus 5.5 b73692ed37 Save states: the whole runtime saved and loaded at the dispatcher's safe point
A state is taken at the top of Dispatcher::run's loop, where no guest code is on
the host stack: memory, the dispatcher, the kernel (threads, frames, queues,
deadlines), every library's state, the native IOP host (memory, tasks, kernel
objects, RPC servers, mixer, libsd) and sections ports add (state::Sections).

Parked library lambdas become data: Resume records and native deadline kinds,
rebuilt from tables on load; ports can add their own kinds. FreeHost serves
requestSave / requestLoad from any thread, rolls back a failed load, and takes
FreeOptions (gameTag, loadState[Frame], saveState[Frame]). Windows get ten slots:
F5 save, F7 load, F6 / Shift+F6 select, and a Save states tab in F2.

989SND's engine and a playing movie are not covered: a save waits, saying why.
docs/save-states.md tells a port how to use and check it; tests/runtime/state_tests.cpp
covers the archive, files and a dispatcher round trip.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 18:22:15 +01:00
Thomas MartinandClaude Opus 5.5 3a520a8af1 Native IRX: no ready tasks run inside a running task
runReady and advance() could be reached while a task was running (its
call into the EE, the EE handler calling back into the IOP), and then ran
the ready tasks nested, the calling task itself too, on its live state.
They now leave the ready tasks to the loop running that task.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 10:02:42 +01:00
Thomas MartinandClaude Opus 5.5 a7e97e61d3 Native IRX vblank 7; module lookup fast paths for ports with many overlays
- vblank 7 (WaitNonVblank) returns at once: there is no display, so never a
  vblank to wait out (Jade Cocoon 2's M2SOUND).
- FunctionTable::moduleAt scanned every module on every lookup (JC2
  registers 1,383 overlay modules, 559 of them sharing 0x940000, so each call
  into a slot compared up to 559 headers). It now rejects addresses outside
  the span all modules cover at once, and asks the module found last first,
  identity checked; the full scan with its ambiguity check is unchanged when
  that misses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-16 04:48:18 +01:00
Thomas MartinandClaude Opus 5.5 42643dd1d3 Native IRX host: vblank waits 4 and 6, data guesses left out of discovery, stuck task named
Jade Cocoon 2's i-mode and sound drivers (Genki's M2IMODE/M2SOUND over Sony's
IMODEMAN, LIBSD, MODMIDI, MODHSYN) on the compiled-library host:
- vblank 4 (WaitVblankStart) and 6 (WaitVblank) wait for the next native frame
  tick, as 5 (WaitVblankEnd) does: no display, the start and end of a vblank
  are one tick. IMODEMAN polls on 4.
- recompile.py: a pointer_seeds guess that cannot be recompiled and that no
  recompiled function calls is data, not a function. It is left out instead of
  failing the module (IMODEMAN.IRX 0x84c10 at base 0x6a100: a data word that
  holds the address after a JR $ra). The entry, exports and --entry addresses
  are never dropped. DC's LIBSD, SDRDRV, MODMIDI, MODHSYN and EZMIDI discover
  the same functions as before.
- "native library tasks made no blocking progress" names each task still
  running and its pc/ra (M2IOPSYS's bind retry loop, for instance).
- BOZO_NATIVE_IRX_TRACE also logs sifcmd 15 (an IOP bind of an EE service).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 23:55:37 +01:00
Marc-Etienne Barrut 32e9157ff0 Merge pull request #91 from TheBozos/ffop/iop-host-imports
[ffop/iop-host-imports] IOP event flags and host services, sync-V callback at the vblank
2026-11-12 04:10:38 +01:00
ArzarothandClaude Opus 5.5 ed36f16c9e [sctpt2/native-irx-cdvdman] feat(native-irx): sysmem's free-memory queries and sifcmd's EE data read
QueryMaxFreeMemSize (7) and QueryTotalFreeMemSize (8) answer from the native
heap. sceSifGetOtherData (23) copies from EE RAM when called.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 03:19:35 +01:00
ArzarothandClaude Opus 5.5 80e6d23598 [sctpt2/native-irx-cdvdman] feat(native-irx): cdvdman's drive commands with nothing to move
init, standby, seek, disk type, disk ready, tray request, stop, clock, status, pause, break and media mode, for
compiled disc callers that set the drive up before reading (a game's own file server). They complete at once; seek,
standby, stop and pause notify the callback with their SCECdFunc code as a read does. The clock is the EE library's
(deterministic unless the host clock is chosen).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 05:44:04 +01:00
ArzarothandClaude Opus 5.5 3449423c4f [ffop/iop-host-imports] feat(native-irx): event flags, QueryIntrContext, bzero and ReferSemaStatus
Fighting for One Piece's STRADPCM waits on IOP event flags and asks
QueryIntrContext which form of a call to make; its SK sound modules
clear with bzero and SKSADPCM reads a semaphore's status. thevent 4-11,
13, 14 are native host objects on the task scheduler, as semaphores
are; waits take AND and OR, the clearing mode fails explicitly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 05:22:41 +01:00
Thomas MartinandClaude Opus 5.5 cc1b03245a Compiled libraries: IOP software registers, sifcmd init/sregs, more cdvdman, opt-in import-time audio completions and root budget
For EA's sound driver in The Third Age (AUDIOPF.IRX), which talks to the EE only
through SIF commands and software registers:
- SifState::iopSreg, the IOP side's 32 software registers: sifcmd
  sceSifGetSreg (6) and sceSifSetSreg (7) read and write them; a module's
  set-sreg system command (sceSifSendCmd 0x80000001, index at +0x10, value at
  +0x14) writes the EE's (sif.sreg). sceSifInitCmd (4) / sceSifExitCmd (5) do
  nothing.
- cdvdman with native disc files: sceCdInit (4) and sceCdMmode (75) answer 1,
  sceCdDiskReady (13) 2, sceCdSearchFile (10) fills sceCdlFILE from the ISO
  directory as the EE library's sceCdSearchFile does.
- useReadyAudioCompletionsAfterImports(): ready audio completions also
  delivered when an import call returns, for a routine that starts a libsd
  transfer then polls its flag in a loop with no call. Opt-in: other ports
  keep their schedule.
- setRootCallBudget(n): the work a root call may do (default 1,000,000
  unchanged); AUDIOPF's start clears its buffers byte by byte.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-09 23:18:58 +01:00
Thomas Martin 959edc85c3 Add opt-in native disc files for compiled libraries 2026-11-07 22:07:45 +01:00
ArzarothandClaude Opus 5.5 f7b7463518 [sc3/mix-half-overrun] fix(native): the mix stops at an input half a task's charge already passed
A task's instructions move the cycle while the mixer stays behind. nextInputHalfCycle then named a cycle already past and the stop was dropped, so the step ran the mix over every half up to its target, with no handler and no refill in between. In SC3 this recurs where a vblank task lands just before a half (39 vblanks against 61 halves): 280-285 stale samples every 31232.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-07 02:00:16 +01:00
ArzarothandClaude Opus 5.5 298ed010bf [sc3/irx-intr-state] fix(native-irx): CpuSuspendIntr and CpuResumeIntr are one flag, a nested suspend needs no resume
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 23:47:23 +01:00
ArzarothandClaude Opus 5.5 06b59c180a [sc3/irx-sound] feat(native-irx): a module's start gets sceSifLoadModule's arguments as argc and argv
Soulcalibur III configures CRI's ADX driver this way (thpri=39, spucore=2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 22:09:14 +01:00
ArzarothandClaude Opus 5.5 b05a8f2573 [sc3/irx-sound] feat(native-irx): IOP calls to native EE services, sifcmd 15, 16, 24, 25
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 22:09:14 +01:00
ArzarothandClaude Opus 5.5 32aef1a3a4 [sc3/irx-sound] feat(native-irx): sysclib strings and sprintf, thread lifecycle, wakeup cancel, timer counter, WaitVblankEnd
sysclib 11, 19, 20, 22, 23, 30, thbase 5, 8, 10, 27, 28, timrman 10, loadcore 7, vblank 5 (a 60 Hz job on
the library clock, no display behind it). printf and Kprintf format their arguments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 22:09:14 +01:00
ArzarothandClaude Opus 5.5 61860f6779 [sc3/irx-sound] feat(libsd): sceSdNote2Pitch, sceSdPitch2Note, GetTransIntrHandlerArgument and StopTrans natively
Exports 13, 14, 28 and 30, so a module needs no LIBSD image at all.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 22:09:14 +01:00
ArzarothandClaude Opus 5.5 7fe36c4988 [sc3/irx-sound] feat(libsd): each signalled input half answered in turn, the host's mix stops at each half
A 4 KiB sceSdBlockTrans ring: a long clock step no longer plays a half before its handler
refilled it, and a status read after the input moved on still names the half to refill.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 22:09:14 +01:00
ArzarothandClaude Opus 5.5 50593f9913 [con/irx-sdrdrv] feat(native-irx): CpuDisableIntr/CpuEnableIntr as a callback-exclusion scope
HELLO.IRX brackets its shared stream state with intrman 8/9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 20:46:14 +01:00
ArzarothandClaude Opus 5.5 4396cf7daf [con/irx-sdrdrv] feat(native-irx): RPC handlers run on their server task
An EE call to a server registered by a compiled module runs the handler
above the server task's parked RpcLoop frame, so it may wait (HELLO.IRX
delays inside its RPC). The host clock goes on to the next deadline until
the handler returns; a failing handler leaves the task parked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 20:44:42 +01:00
ArzarothandClaude Opus 5.5 7d071d13ca [con/irx-sdrdrv] feat(native-irx): IOP alarms as native periodic jobs
thbase SetAlarm, iSetAlarm, CancelAlarm, iCancelAlarm and USec2SysClock
(35-39) for HELLO.IRX: the linked handler runs on the host's timer
scheduler, its return value is the next interval, zero ends it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 20:42:24 +01:00
ArzarothandClaude Opus 5.5 80d5e86fcd [con/irx-sdrdrv] feat(native-irx): sysmem Kprintf prints as stdio printf
SDRDRV.IRX prints its banner with Kprintf at start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 20:42:24 +01:00
boubou666andThomas Martin 7a82355432 Deliver compiled user replies through a native application receiver (#26)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 18:26:20 +01:00
boubou666andThomas Martin 9c4a00d9cf Expose checked spans into live native library allocations (#25)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 18:13:29 +01:00
boubou666andThomas Martin f26d41f297 Dispatch bounded native user commands to linked handlers (#24)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 18:04:51 +01:00
boubou666andThomas Martin 284402659e Deliver compiled frame listeners from actual native game frames (#23)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 17:58:45 +01:00
boubou666andThomas Martin 9bc4acff04 Schedule native timer handlers with explicit lifecycle (#22)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 17:50:34 +01:00
boubou666andThomas Martin 30761f5e2e Deliver ready native audio completions at linked safe points (#21)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 17:46:14 +01:00
boubou666andThomas Martin 248d39c83b Grant native priority semaphore waits from current task priorities (#20)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 17:34:31 +01:00
boubou666andThomas Martin f824703e3f Copy native library data to checked EE spans with completions (#19)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 17:10:24 +01:00
boubou666andThomas Martin d6ee73ef44 Protect native callbacks with balanced exclusion scopes (#18)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 17:02:21 +01:00
boubou666andThomas Martin 12c29d78bd Retain native RPC owner task identity and priority (#17)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 16:53:50 +01:00
boubou666andThomas Martin 7060102847 Implement bounded native library memset service (#16)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 16:46:26 +01:00
boubou666andThomas Martin 1b6f1ed8e2 Bind per-host native algorithms at admitted library entries (#15)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 16:25:15 +01:00
boubou666andThomas Martin 28f9708875 Implement native library FIFO semaphore services (#14)
Co-authored-by: Thomas Martin <[email protected]>
2026-11-06 16:07:13 +01:00
Thomas Martin 56df451cef Allow native timer callbacks to cancel due timers safely 2026-11-06 09:37:30 +01:00
Thomas Martin 11cb6df323 Add reusable native image, compiled-library and port services 2026-11-06 02:47:13 +01:00