Repository navigation
Dark Forces: every level fits on the box (JABSHIP loads; finishing NARSHADA no longer crashes) - #146
Merged
Merged
Conversation
…the Tab5) All of the firmware's code (2.4 MB, 39 MMU pages) was copied into PSRAM at boot (CONFIG_SPIRAM_FETCH_INSTRUCTIONS), every emulator core's included, although only one runs at a time. Now every core's code is linked at one instruction-bus address (0x43800000) and only the running core's is copied into PSRAM, mapped there when its game launches (components/core_overlay): - tools/core_overlay.py rename (POST_BUILD of each core's library, core_overlay_archive()): the archive's .literal* / .text* become .core_ovl.<core>.*, its .ctors the member's constructor table (run on the core's first load). COMDAT code (shared inline / template code the linker keeps one copy of) stays resident, and so does Dark Forces' allocator (its firmware-wide free()/realloc() wrappers). - overlay.ld: the OVERLAY (NOCROSSREFS: a link error if one core's code references another's). The linked bytes go into a flash store in .flash.rodata (src/store.c, sized before the link from the archives) after linking (tools/core_overlay.py image), which also checks that nothing resident reaches into the overlay except the carts, the loader and a core's own tables and code. - src/core_overlay.c: at launch a 64 KB-aligned PSRAM heap block is mapped a second time at the overlay address (esp_mmu_map_virt, executable), the core's code is copied in, the data cache written back and the instruction cache invalidated; it is unmapped and freed when the cart is gone. The rest of the firmware's code stays copied into PSRAM (the S3 has no L2 cache to hide flash's slower fetches): code in PSRAM at boot 2.4 MB -> 949 KB (15 pages); a launch maps 64 KB (GBC) to 384 KB (Dark Forces). On the box (PSRAM free; before -> after): - launcher 941 KB -> 2480 KB (largest block 656 KB -> 2432 KB) - Dark Forces: title ~705 KB -> 1841 KB; Talay 123-176 KB -> 1275 KB; a save loaded inside Talay 32 KB -> 1184 KB Speed is unchanged (the cores' code still runs from PSRAM): Talay renders in 13.0 ms (12.9 before), Genesis stays at 60 fps with 3.4-6.5 ms to spare per frame. Every core launches, runs and quits (NES, GBC, SMS, GG, MSX, Genesis, Doom, PICO-8, Dark Forces; NES, SMS and MSX twice), with and without sound; loads take 2-18 ms. The overlay's link check found a latent bug: fMSX's Z80 called the Genesis core's PatchZ80 stub (both define one; the linker resolved fMSX's call to the Genesis one), so fMSX's own (fMSX/Patch.c, the ED FE disk BIOS traps) was never linked. libmsx.a's is renamed fmsx_PatchZ80 (symbol_renames.syms, as on the Tab5). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
…g NARSHADA no longer crashes) TheForceEngine perf/df-level-memory 5f5b0da: only the textures a level uses are loaded (JABSHIP: 51 of 359, -1.1 MB), the level is freed before the next mission's cutscene starts, the renderer's adjoin edge list (-253 KB) and the task stacks (-96 KB per 16 tasks) are their real size, and a save load frees the loaders' read buffers. Tested with the code overlay (#145), PSRAM free: Talay 1778 KB (1275 before); NARSHADA 1431 KB, and finishing it (LASKIP) plays jabba1 and loads JABSHIP (crashed before); JABSHIP directly 1762 KB (could not load before); ARC 937 KB, a save made in ARC loads back in it (795 KB) and from the title. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
…d constructors in order; archives rebuild when their tools change From a review of the overlay: - core_overlay_unload() waits 20 ms before unmapping: a core's helper task that deletes itself (the Genesis sound task, Dark Forces' MIDI thread) signals its owner just before vTaskDelete(), so its last instructions still run from the overlay. (Today a 50 ms sleep in the Genesis teardown happens to cover it; nothing guaranteed it.) - A prioritised constructor table .ctors.NNNNN (init_priority 65535 - NNNNN) is renamed by its priority, so overlay.ld's SORT by name runs it in priority order (none of the cores uses init_priority today). - A library's POST_BUILD steps (the overlay rename, fMSX's symbol renames) have no inputs, so editing core_overlay.py or symbol_renames.syms left the archives as they were: core_overlay_rebuild_on() makes one of the library's objects depend on the file (LINK_DEPENDS does not reach a static library's archive step). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
…, as CI does) esp_mmu_map_virt() is new in IDF 6.1; CI builds with 6.0.1. The window is now mapped the way IDF's MMU driver does it internally: with the caches and the other CPU stopped (spi_flash_disable_interrupts_caches_and_other_cpu), from internal RAM, mmu_hal_map_region() / mmu_hal_unmap_region() and the cache bus enabled; the instruction cache is invalidated with esp_cache_msync() as before. One path for every IDF version (CI's release builds run the same code). The driver does not track the window; it lies far above everything the firmware maps. Also: pointer arithmetic on the linker symbols through uintptr_t (cppcheck subtractPointers). On the box: all eight cores launch, run and quit (NES twice), Dark Forces loads Talay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
…y.map (idf.py size parses the map)
In the map the overlay members are output sections at one address with load
addresses of their own (".core_ovl.gbc 0x43800000 0xb5e0 load address
0x43810020"), which esp-idf-size cannot parse: idf.py size, and CI's size
delta step, failed. The image step moves them (and the overlay's symbol
assignments) into <app>.core_overlay.map; the code they hold is counted where
it is in flash, in the store in .flash.rodata. idf.py size now reports flash
code 972 KB (was 2.4 MB) and flash data 3.6 MB with the store.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
|
✅Static analysis result - no issues found! ✅ |
ESP-IDF Size Report for 'Esp Box Emu'
FLASH uses app .bin size or json2 flash sum. RAM sums DRAM+IRAM via idf_size. Percentages shown when totals are available. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bumps TheForceEngine to esp-cpp/TheForceEngine#3. With it, every Dark Forces level fits on the box, alongside the code overlay of #145:
#145 and esp-cpp/TheForceEngine#3 are merged; this is now only the submodule bump.
Testing on the box (muted)
Before and after, PSRAM free:
The whole campaign goes from SECBASE through ARC with the game's own
LASKIP, then the ending and the credits. The lowest point is ARC at 787 KB free after the thirteen levels before it, and there was no crash or failed allocation. Details are in esp-cpp/TheForceEngine#3.Saves and other cores:
🤖 Generated with Claude Code
https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY