Initial CTR IPC/services (3a)

SVC 0x2d connects to the actual srv: endpoint; 0x32 dispatches checked TLS command words; 0x35 identifies the actual process root. A separate SwIPC --ctr mode emits typed handlers without HIPC/CMIF or successful default stubs. srv: supports client registration and service lookup with real session ownership. Initial 3b adds a one-application APT startup lifecycle, real recursive lock/events, serialized thread contexts/waits/wakeups, PTM base/model queries and HID handles/read-only mapping. HID sampling is implemented as described below. FS supports PID/SDK initialization, read-only SelfNCCH RomFS OpenFileDirectly, and the read-write SDMC archive (9) on the title's folder: OpenArchive, OpenFile, CloseArchive, CreateFile, DeleteFile, CreateDirectory, DeleteDirectory, Rename, OpenDirectory, and FSFILE Read, Write, GetSize, SetSize and Close. Archive tokens are FS-private monotonic 64-bit identifiers, not kernel handles. 32 live bindings are allowed and stale IDs never revive. NX and CTR share common/filesystem/ indexing, immutable file mappings and fallback opens, not their IPC protocols or RomFS metadata. The extracted romfs/ is used when there is an extraction; otherwise the source NCCH's level-3 image is read where it lies. Save data (4) and ExtSaveData (6, in sdmc/Nintendo 3DS/<id0>/<id1>/extdata/, and the shared 7, in nand/data/<id0>/extdata/, as the console lays them out) are on the title's folder too, and so is another title's save data (0x567890B2 and 0x567890B4, in sdmc/Nintendo 3DS/<id0>/<id1>/title/). SelfNCCH also serves the ExeFS icon, logo and banner. The NCCH archive (0x2345678A) serves the title's own RomFS, and in place of the system titles no console here has, the open stand-ins Azahar carries (cmake/ctr_system_archives.cmake, generated by B3n30/citra_system_archives): the country list, the shared font (also for the Chinese, Korean and Taiwanese fonts) and the bad word list. The Mii data (0004009B00010202) is ScarletNX's own, made at its first open: the Mii parts a game's face library builds a head from, CFL_Res.dat in the layout the stand-in generator's mii.py writes, from the same plush shapes and drawings as the Switch's MiiModel (Filesystem), each mesh with no more than the 256 vertices a byte indexes, every texture RGBA4. Another system title is NotFound. Directory sessions read their entries, and FSFILE has Flush, priorities and OpenLinkFile. Reads preflight the complete guest destination and stage host IO before publication. GetSystemTick and the shared page's date and time (the host's local time, rewritten every hour into the entry the counter does not select, as Azahar does) serve time queries, without cycle accuracy. Every deadline, sleep and tick of the runtime is on one clock (board/clock.c): the host's at the console's pace, which the Switch's fps_limit sets as for a Switch game. N runs it at N/60 of the console's pace (the 3DS shows 60 frames a second), the sound with it; 0 skips every wait, the clock moving on by it, so the game runs as fast as the host does and its sound is not played; F4 turns the limit off and back on, the terminal saying the limit now and before it as a Switch game does (FPS limit: off (was the game's pace)). A change of pace never moves the clock back. FSUSER ControlArchive GET_TIMESTAMP (0x80d) resolves a bounded UTF-16 archive path and returns the real backing file's host modification time as a 3DS datetime (milliseconds since 1900 UTC). Missing paths return 0xc8804478 and stale tokens 0xc8804465. COMMIT_SAVE_DATA on the SDMC area succeeds, since every write has already reached the host, and other actions stop. Unknown commands answer success with one word, as Azahar's ReportUnimplementedFunction does and a Switch game's do (auto_stub_ipc), each logged the first time. A service the runtime does not know at all is a stand-in whose commands answer so, as a Switch game's is (sm.c). With --ctr-auto-stub-ipc=0 both stop instead: an unknown command stops the run unless --ipc-stubs names its service, and a service the runtime lacks makes the thread asking for it wait forever, as no other process can register it, with a message that names it.

hid:USER and hid:SPVR (services/hid.c, ported from Azahar's hid.cpp) write the pad's samples into HID's shared memory 234 times a second from the first GetIPCHandles, each with both pad events signalled, and the accelerometer's (104 a second) and the gyroscope's (101) between their enable and disable. Each pad entry has the buttons, what was pressed and released since the one before, and the circle pad's position, averaged over three samples, with its direction bits. The input (src/3ds/input/input.c) is a Switch game's: X or Space A, Z B, C X, V Y, Q L, E R, 1 ZL, 3 ZR, Enter Start, Backspace Select, the arrows the D-pad, WASD the circle pad and IJKL the C-stick, or a gamepad's buttons by position (the triggers ZL and ZR), gamepad_map over that (the Switch's button names: Plus is Start, Minus Select), A swapped with B by gamepad_swap_ab, with its left stick the circle pad and its right one the C-stick past gamepad_deadzone, all three the Switch's settings, and the scripted presses of --script=ms:hex,... (ctr_script), in the pad's bits (1 A, 2 B, 4 Select, 8 Start, 10 Right, 20 Left, 40 Up, 80 Down, 100 R, 200 L, 400 X, 800 Y, 4000 ZL, 8000 ZR), each held for press_len ms. The touch entries follow a finger or the mouse's left button pressed on the bottom screen, as the Switch's touch says (2 both, 1 fingers, 0 neither), one at a time: the first pressed holds the screen until it lets go. The accelerometer and gyroscope are the first gamepad whose motion sensors SDL reads (its own, else a left or right Joy-Con's), as the Switch's backend reads them (snx_pad_motion_read), in the axes of Azahar's SDL motion (y of the acceleration and x and z of the rotation negated), at 512 raw a g and 14.375 a degree a second; a pad held up in front of the player at rest reads as the console at rest. With no such pad they give a console lying still.

ZL, ZR and the C-stick are the New 3DS's ir:rst (services/irrst.c, ported from Azahar's ir_rst.cpp). GetHandles moves out its shared memory and update event, and from Initialize to Shutdown each update_period ms writes the next of eight entries: ZL, ZR and the C-stick's direction bits (the circle pad's rule, four bits down), what they gained and lost since the entry before, and the C-stick's position, 0x9c at its rim, then signals the event. A period of 0 samples every millisecond and the raw C-stick, which Azahar does not model either, gives the position without its direction bits; each is said on the standard error with the value asked for.

mic:u (services/mic.c, ported from Azahar's mic_u.cpp) answers as Azahar does with no input device: sampling starts and stops, the settings a game stores (gain, power, clamp, the shell closed) read back, and the buffer full event is a real event that is never signalled, as no sample is ever written.

cam:u (services/cam.c, ported from Azahar's cam.cpp) has Azahar's blank camera behind it: the ports activate, capture and receive as Azahar's do, a receiving completes at its camera's frame rate's latency with a black frame (whole or trimmed, YUV422 or RGB565), an activated port's vsync event fires at that latency and GetLatestVsyncTiming gives the last five. A frame rate or a size preset past Azahar's tables, and a width of 0, which Azahar would read past or divide by, are refused with InvalidEnumValue and OutOfRange.

csnd:SND (services/csnd.c, with the CSND hardware in audio/csnd.c, ported from Azahar's csnd_snd.cpp and csnd.cpp) plays: each session gets its shared memory and mutex at Initialize, and the command lists the game writes there configure, start, pause and stop the 32 channels (PCM8, PCM16, IMA-ADPCM; one-shot, looping, held; linear interpolation), with Azahar's 40-step volume fades before a pause or a stop, and write back the state the game reads. While a session is initialized or a channel plays, the hardware renders a frame each DSP frame time, a command landing at the sample it comes at, and the frame is mixed into the DSP's output as Azahar mixes it, or played alone when the DSP is idle. PSG and noise play silence and the capture units capture nothing, as in Azahar.

ir:USER (services/ir.c) answers as Azahar does with no IR accessory in range. InitializeIrNopShared writes the shared block's header and empty receive queue, the receive, send and connection-status events are real kernel events, and RequireConnection only marks the header as trying to connect, so the status event never fires and a game that waits on it goes on without the accessory. SendIrNop answers that nothing is connected. The commands with no model answer success with zeros, as the other system services do.


Made from docs/platforms/3ds/README.md at 69237645142c. GPL-3.0-or-later.