A DS has two processors. The ARM9 runs the game. The ARM7 runs a program that is the SDK's own, the same in every game but for its version: it serves the sound hardware, the touch screen, the clock, the power chip, the firmware's flash, the card's save memory and the wireless hardware, and the game's ARM9 side asks it for each over a FIFO between the processors. The ARM9 also calls the console's BIOS, and it starts in the state the firmware leaves.
scarletnx-nds runs the ARM9's code alone, compiled. The ARM7 is a set of answers
(The ARM7's services), the BIOS a set of routines (The HLE BIOS), and the
firmware a starting state: the header and the program in main memory, the user's settings, CP15's registers and the
stacks, as melonDS's direct boot sets them. The hardware the ARM9 reaches itself has its registers
(src/nds/board/io.c): the display's, the DMA channels, the timers, the divider and the square root, the keys, the
card's slot, the interrupt controller, and the 3D engine's.
The board keeps the console's time in bus cycles (33.51 MHz). A compiled block is charged a cycle for every two instructions. Events come at their cycle: each line's horizontal blank and end, a timer's overflow, the sound driver's tick and its alarms. A DMA transfer and a geometry command take no time: a transfer runs whole when it starts, and a command runs when it is written. So does a read of the card: a block is all there when its command is written, a DMA channel that waits for the card takes it at once, and the card's interrupt follows. The commands after SWAP_BUFFERS are the exception, which wait for the vertical blank in a queue, as the console holds them, and the geometry engine says it is busy until then.
Made from docs/platforms/nds/README.md at 69237645142c. GPL-3.0-or-later.