Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/n3ds-platform/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ osSetSpeedupEnable(true); // Boost CPU to 804 MHz and enable L2 cache
`<devkitPro>/msys2/usr/bin/bash.exe -lc "export DEVKITPRO=/opt/devkitpro DEVKITARM=/opt/devkitpro/devkitARM; cd <repo> && make -C build/3ds -j10"`
(first time: `cmake -S platform/3ds -B build/3ds -G 'Unix Makefiles' -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake -DCMAKE_BUILD_TYPE=Release`, plus `-DPython3_EXECUTABLE=<host python>` if msys2 has none).
- Code size is the constraint (docs/3DS_PLATFORM.md 8.5). Never add a define that changes `Runtime`'s layout to only some targets; a define that changes compile flags of `p3p_aot` rebuilds all 237 units (~9 min) — put runtime-only defines on `psprecomp_runtime`.
- Test in Azahar (New 3DS mode) with the ISO in its virtual `sdmc/p3p3ds/`. Read `sdmc/p3p3ds/report.txt`: `stage`, heap size/in use, and `failed alloc: <bytes> from <addr>`; resolve the address with `arm-none-eabi-addr2line -f -C -i -e build/3ds/p3p3ds.elf <addr>`. The maintainer may be running Azahar too: do not kill an instance you did not start, and do not trust a report without checking its build id and timestamp. Screenshot of the Azahar window: `powershell -NoProfile -ExecutionPolicy Bypass -File .claude/skills/n3ds-platform/scripts/azahar_shot.ps1 -Out .tmp/azahar/shot.png`. A crash photo of the Luma exception screen gives PC and LR: resolve both with addr2line on the ELF of exactly that build (`build <id>` in the report).
- Test in Azahar (New 3DS mode) with the ISO in its virtual `sdmc/p3p3ds/`. A run that is killed never writes its final report, so put an empty `sdmc/p3p3ds/report_live.txt` there first (report every 5 s), or quit with START+SELECT. Read `sdmc/p3p3ds/report.txt`: `stage`, heap size/in use, and `failed alloc: <bytes> from <addr>`; resolve the address with `arm-none-eabi-addr2line -f -C -i -e build/3ds/p3p3ds.elf <addr>`. The maintainer may be running Azahar too: do not kill an instance you did not start, and do not trust a report without checking its build id and timestamp. Screenshot of the Azahar window: `powershell -NoProfile -ExecutionPolicy Bypass -File .claude/skills/n3ds-platform/scripts/azahar_shot.ps1 -Out .tmp/azahar/shot.png`. A crash photo of the Luma exception screen gives PC and LR: resolve both with addr2line on the ELF of exactly that build (`build <id>` in the report).
- Never write `sdmc` or emulator paths of the maintainer's machine into tracked files.

## 3b. P3P3DS Builder release
Expand Down
2 changes: 1 addition & 1 deletion .claude/skills/n3ds-platform/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ osSetSpeedupEnable(true); // Boost CPU to 804 MHz and enable L2 cache
`<devkitPro>/msys2/usr/bin/bash.exe -lc "export DEVKITPRO=/opt/devkitpro DEVKITARM=/opt/devkitpro/devkitARM; cd <repo> && make -C build/3ds -j10"`
(first time: `cmake -S platform/3ds -B build/3ds -G 'Unix Makefiles' -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake -DCMAKE_BUILD_TYPE=Release`, plus `-DPython3_EXECUTABLE=<host python>` if msys2 has none).
- Code size is the constraint (docs/3DS_PLATFORM.md 8.5). Never add a define that changes `Runtime`'s layout to only some targets; a define that changes compile flags of `p3p_aot` rebuilds all 237 units (~9 min) — put runtime-only defines on `psprecomp_runtime`.
- Test in Azahar (New 3DS mode) with the ISO in its virtual `sdmc/p3p3ds/`. Read `sdmc/p3p3ds/report.txt`: `stage`, heap size/in use, and `failed alloc: <bytes> from <addr>`; resolve the address with `arm-none-eabi-addr2line -f -C -i -e build/3ds/p3p3ds.elf <addr>`. The maintainer may be running Azahar too: do not kill an instance you did not start, and do not trust a report without checking its build id and timestamp. Screenshot of the Azahar window: `powershell -NoProfile -ExecutionPolicy Bypass -File .claude/skills/n3ds-platform/scripts/azahar_shot.ps1 -Out .tmp/azahar/shot.png`. A crash photo of the Luma exception screen gives PC and LR: resolve both with addr2line on the ELF of exactly that build (`build <id>` in the report).
- Test in Azahar (New 3DS mode) with the ISO in its virtual `sdmc/p3p3ds/`. A run that is killed never writes its final report, so put an empty `sdmc/p3p3ds/report_live.txt` there first (report every 5 s), or quit with START+SELECT. Read `sdmc/p3p3ds/report.txt`: `stage`, heap size/in use, and `failed alloc: <bytes> from <addr>`; resolve the address with `arm-none-eabi-addr2line -f -C -i -e build/3ds/p3p3ds.elf <addr>`. The maintainer may be running Azahar too: do not kill an instance you did not start, and do not trust a report without checking its build id and timestamp. Screenshot of the Azahar window: `powershell -NoProfile -ExecutionPolicy Bypass -File .claude/skills/n3ds-platform/scripts/azahar_shot.ps1 -Out .tmp/azahar/shot.png`. A crash photo of the Luma exception screen gives PC and LR: resolve both with addr2line on the ELF of exactly that build (`build <id>` in the report).
- Never write `sdmc` or emulator paths of the maintainer's machine into tracked files.

## 3b. P3P3DS Builder release
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Every known issue is tracked on [GitHub Issues](https://github.com/endercodezz/P
| ATLUS and CRIWARE startup logos were missing ([#5](https://github.com/endercodezz/P3P3DS/issues/5)) | first seconds after start, 0.2.8-0.3.1 | fixed in 0.3.2 by rebinding textures after presenting a frame. The fix was verified in Azahar, and the maintainer reported working logos on console. |
| Scene transitions: one or more black frames instead of a fade ([#3](https://github.com/endercodezz/P3P3DS/issues/3)); garbage on hardware until 0.3.0 | cutscene and scene changes | since 0.3.1 black on hardware and in Azahar alike (new render targets are filled black); the missing fade itself is not fixed |
| Light fringe around changed facial expressions in dialogue portraits ([#4](https://github.com/endercodezz/P3P3DS/issues/4)) | dialogue | [UNVERIFIED] linear filtering of the overlay sprite samples outside its rectangle |
| 0.3.0 only: on a slow SD card the game stops for seconds every 5 s while it rewrites `report.txt` (one user: 36 % speed, `ui` about 60 %) | everywhere | fixed in 0.3.1, confirmed on hardware by the same user: 97-99 % speed, `ui 0.0`, while one rewrite still takes up to 2.6 s on that card (`sd max 2575 ms`) |
| Up to 0.3.3: on a slow SD card the game freezes every 5 s while `report.txt` is rewritten (0.3.0: the game itself waited, 36 % speed; 0.3.1-0.3.3: the rewrite runs in the background but the game's reads can wait behind it, 64 % speed in one run) | everywhere | the report is no longer written during play unless you touch the bottom screen; not yet confirmed on hardware |
| Battle: 16-25 fps, 63-86 % of real time (0.3.0, hardware; was 5-7.5 fps in 0.2.7) ([#16](https://github.com/endercodezz/P3P3DS/issues/16)) | battles | game targets 30 fps; the game's own code is now the largest share (`aot` 63-70 %) |
| Dorm: 28-30 fps (0.3.0, hardware) ([#17](https://github.com/endercodezz/P3P3DS/issues/17)) | field | game targets 30 fps |
| No sound ([#14](https://github.com/endercodezz/P3P3DS/issues/14)) | everywhere | not implemented on 3DS (the PC runner mixes it) |
Expand Down Expand Up @@ -53,7 +53,7 @@ On New 3DS (details in [`docs/3DS_PLATFORM.md`](docs/3DS_PLATFORM.md) sections 8
| Saves | save and load at the dorm desk and from LOAD GAME, menu on the bottom screen |
| First battle | starts since 0.2.5; transform, skinning and lighting on the GPU since 0.2.6; renders correctly since 0.2.7 (culling fix); slow (see Known issues) |
| Memory | heap 71,220 KiB with 60,284 KiB in use (hardware, 2026-10-02; 12 MiB linear heap); about 10.7 MiB free |
| Screens | top: the game; bottom: authorship and debug data (fps, speed, where the time went over the last 10 s, memory), also saved to `sdmc:/p3p3ds/report.txt` |
| Screens | top: the game; bottom: authorship and debug data (fps, speed, where the time went over the last 10 s, memory), also saved to `sdmc:/p3p3ds/report.txt` at the start, on exit and when you touch the bottom screen |

Measured on the PC runner (ULUS-10512, details and evidence in [`docs/CURRENT_STATE.md`](docs/CURRENT_STATE.md)):

Expand Down Expand Up @@ -139,7 +139,7 @@ The builder package (about 2 MB zipped) contains no game data: only the prebuilt
The runner creates `p3p3ds/ms0/` (memory stick), `p3p3ds/mods/` (mod chain, see below) and `p3p3ds/report.txt` itself.
2. Start **P3P3DS** from the Homebrew Launcher.

The top screen shows the game, the bottom screen authorship and a live debug report (fps, speed, memory, time split), also written to `sdmc:/p3p3ds/report.txt` every few seconds and on exit — please attach it to bug reports.
The top screen shows the game, the bottom screen authorship and a live debug report (fps, speed, memory, time split), also written to `sdmc:/p3p3ds/report.txt` at the start, on exit (START+SELECT) and whenever you touch the bottom screen — please attach it to bug reports. An empty `sdmc:/p3p3ds/report_live.txt` also writes it every 5 s, for runs that crash before you can quit; on a slow SD card that can make the game freeze for a moment.

| 3DS | PSP |
|---|---|
Expand Down
10 changes: 10 additions & 0 deletions docs/CURRENT_STATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

This is the current source of truth, newest entries first. Evidence concerns ULUS-10512; each section says whether it was measured on the PC runner, in Azahar or on a real New 3DS.

## No report.txt writes during play on the New 3DS (#71, #66, 2026-11-06)

- [VERIFIED] User reports on #66 (New 2DS XL, 0.3.2 build 2f91246, same Samsung EVO Plus 64 GB, attached report.txt and profile_seconds.csv): a run with freezes about 5 s apart had `sd max 2656 ms`, `io 36` (last 10 s), speed 64-74 %; a run without freezes had `sd max 78 ms`, `io 0`, speed 96-99 %.
- [INFERRED] The card's write latency varies between sessions, and while a slow background rewrite runs, the game's ISO reads wait behind it. Not measured directly: no per-second CSV exists of a run with freezes.
- `platform/3ds/main.cpp`: the bottom screen still updates every 5 s, but report.txt is written only at the start of the run (build and `status : running`, before the game reads anything), on exit, and when the bottom screen is touched (through the writer thread; the PSP has no touch screen, so the game never sees it). The new row `report : touch to save, N written` replaces the blank row 5 of the report, so the other rows stay where they were. An empty `sdmc:/p3p3ds/report_live.txt` restores the write every 5 s, for runs that end without an exit (a host crash, a killed emulator).
- [VERIFIED] Azahar, unattended autotest of 1,500 vblanks, this branch: without `report_live.txt` report.txt changed only at the start and at the end (`2 written` in the final report: `booting` and the start write); with it, every 5-6 s (`6 written`). Same speed in both (83 %), so Azahar says nothing about the stall itself: its SD writes take 50 ms.
- [UNVERIFIED] The tap itself was not exercised: a click posted to Azahar's windows did not reach the game (`2 written`). The write path it uses is the one `report_live.txt` ran above, and `hidKeysDown` reports the first frame of a touch [VERIFIED] `3ds/libctru/libctru/source/services/hid.c:199,204`.
- [UNVERIFIED] Hardware with a slow card: no periodic freezes and speed near 97-99 % in the same scene. Needs the reporter's confirmation on the next release. A host crash now leaves only the start report unless `report_live.txt` is present.
- `profile_seconds.csv` (opt-in) still writes every second on the game's thread, so it can disturb a slow card itself.

## Builder 0.3.3 release preparation (2026-11-05)

- `platform/pc/builder/builder.rc` FileVersion and ProductVersion 0.3.3 ([#69](https://github.com/endercodezz/P3P3DS/issues/69)). Contents since 0.3.2: Builder update notice (#67), texture packs (texpack converter, PPSSPP-compatible keys, replacement on the PC and in the 3DS renderer), native game preparation (#33), host time audit docs (#50), Zig BinDiff tool.
Expand Down
40 changes: 30 additions & 10 deletions platform/3ds/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
//
// Top screen: the PSP framebuffer (480x272) scaled to 400x240 (nearest).
// Bottom screen: authorship and live debug information; the same data is
// written to sdmc:/p3p3ds/report.txt every few seconds and on exit.
// written to sdmc:/p3p3ds/report.txt at the start, on exit and when the bottom
// screen is touched. An empty sdmc:/p3p3ds/report_live.txt also writes it every
// 5 s, for runs that may end without an exit (a crash, a killed emulator): the
// writes can hold up the game's reads on a slow SD card.
//
// Game data: sdmc:/p3p3ds/*.iso (the user's ULUS-10512 image) mounted as
// disc0:, sdmc:/p3p3ds/ms0 as ms0:, sdmc:/p3p3ds/mods as the profile's mod directory.
Expand Down Expand Up @@ -98,6 +101,8 @@ constexpr const char *kBase = "sdmc:/p3p3ds";

struct Stats {
u64 start_ms{}, last_report_ms{}, last_fps_ms{};
bool report_live{}; // report_live.txt: report.txt every 5 s
std::uint32_t report_writes_shown{}; // `written` count on the bottom screen
std::uint64_t frames{}, frames_at_last_fps{};
// Game frames: changes of the displayed PSP framebuffer (the game swaps
// buffers once per finished frame); vblanks run at 60/s at full speed.
Expand Down Expand Up @@ -189,8 +194,9 @@ std::deque<TimeSample> g_samples;
// sdmc:/p3p3ds/profile_seconds.txt present: one CSV line per second with the
// split of that second, to find short slowdowns the 10 s report averages out.
FILE *g_seconds_log = nullptr;
// Longest rewrite of report.txt so far (shown as `sd max`).
// Longest rewrite of report.txt so far (shown as `sd max`) and rewrites so far.
std::atomic<std::uint32_t> g_report_write_max_ms{};
std::atomic<std::uint32_t> g_report_writes{};

// 3DS buttons -> PSP buttons by position (PSP: Cross bottom, Circle right,
// Square left, Triangle top).
Expand Down Expand Up @@ -611,7 +617,7 @@ std::string report_text(const Stats &s, const psprecomp::Runtime &rt, p3p3ds::Ke
"static recompilation port\n"
"by %s\n"
"build %s\n"
"\n"
"report : touch to save, %lu written\n"
"status : %s\n"
"fps : %.1f game frames/s (%.0f vblank/s)\n"
"speed : %.0f%% of real time\n"
Expand All @@ -625,7 +631,7 @@ std::string report_text(const Stats &s, const psprecomp::Runtime &rt, p3p3ds::Ke
"stop : %s\n"
"%s"
"\nSTART+SELECT: quit\n",
kAuthor, P3P3DS_BUILD_ID, s.status.c_str(), s.fps, s.vblank_rate, wall > 0 ? 100.0 * guest / wall : 0.0, guest, wall,
kAuthor, P3P3DS_BUILD_ID, static_cast<unsigned long>(g_report_writes.load(std::memory_order_relaxed)), s.status.c_str(), s.fps, s.vblank_rate, wall > 0 ? 100.0 * guest / wall : 0.0, guest, wall,
static_cast<unsigned long long>(s.frames), static_cast<unsigned long long>(k.threads().vblank_count()),
static_cast<unsigned long>(s.buttons),
static_cast<unsigned long>(osGetMemRegionFree(MEMREGION_APPLICATION) / 1024u),
Expand All @@ -644,12 +650,16 @@ void write_report(const std::string &text) {
}
const auto ms = static_cast<std::uint32_t>(osGetTime() - start);
if (ms > g_report_write_max_ms.load(std::memory_order_relaxed)) g_report_write_max_ms.store(ms, std::memory_order_relaxed);
g_report_writes.fetch_add(1u, std::memory_order_relaxed);
}

// The periodic report.txt is written by a thread of its own on core 0 below
// During play report.txt is written by a thread of its own on core 0 below
// the game's priority: on a slow SD card one rewrite took about 3 s (user
// report, 0.3.0: `ui` 60 % of the time, 36 % speed) and the game stood still
// for it every 5 s. The writer's file-system request blocks only the writer.
// for it every 5 s. The writer's file-system request blocks only the writer,
// but the game's ISO reads still share the card with it (issue #71: freezes
// every 5 s with `sd max 2656 ms`, none with 78 ms on the same card), so it
// writes only on request unless report_live.txt asks for every 5 s.
struct ReportWriter {
LightLock lock;
LightEvent wake;
Expand Down Expand Up @@ -891,6 +901,7 @@ int main() {
std::fclose(f);
if (stats.dump_every) std::filesystem::create_directories(std::string(kBase) + "/frames", ec);
}
if (FILE *f = std::fopen("sdmc:/p3p3ds/report_live.txt", "r")) { stats.report_live = true; std::fclose(f); }
if (FILE *f = std::fopen("sdmc:/p3p3ds/profile_seconds.txt", "r")) {
std::fclose(f);
g_seconds_log = std::fopen("sdmc:/p3p3ds/profile_seconds.csv", "w");
Expand Down Expand Up @@ -966,6 +977,11 @@ int main() {
rt.stop("Quit by user (START+SELECT)");
throw psprecomp::FrontierHalt{};
}
if (hidKeysDown() & KEY_TOUCH) { // the PSP has no touch screen: free for the runner
const u64 ui_start = svcGetSystemTick();
post_report(report_text(stats, rt, kernel));
stats.ui_ticks += svcGetSystemTick() - ui_start;
}
{
const double guest_us = static_cast<double>(kernel.threads().now());
const double wall_us = static_cast<double>(svcGetSystemTick() - stats.run_start_ticks) / ticks_per_us;
Expand Down Expand Up @@ -1009,19 +1025,23 @@ int main() {
log_second(g_samples[g_samples.size() - 2], g_samples.back(), rt);
stats.ui_ticks += svcGetSystemTick() - log_start;
}
// Report every 5 s (bottom screen and SD card): redrawing it each
// second cost 8 % of the time in battle on hardware.
if (now - stats.last_report_ms >= 5000u) {
// Bottom screen every 5 s: redrawing it each second cost 8 % of
// the time in battle on hardware. Sooner after a save by touch,
// to show the new count.
const std::uint32_t writes = g_report_writes.load(std::memory_order_relaxed);
if (now - stats.last_report_ms >= 5000u || writes != stats.report_writes_shown) {
const u64 ui_start = svcGetSystemTick();
const std::string text = report_text(stats, rt, kernel);
if (!save_menu.active) show(text);
post_report(text);
if (stats.report_live && now - stats.last_report_ms >= 5000u) post_report(text);
stats.report_writes_shown = writes;
stats.last_report_ms = now;
stats.ui_ticks += svcGetSystemTick() - ui_start;
}
}
};
stage = "run";
write_report(report_text(stats, rt, kernel)); // a run that crashes still leaves its build and `status : running`
start_report_writer();
std::printf("Starting game...\n");
try { rt.run(entry, ~0ull); }
Expand Down