Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
67e98bd
Add adaptive widescreen mod on current shared runtime
mstan Sep 14, 2026
8d0c646
Document renderer draft follow-ups and add screenshots
mstan Sep 14, 2026
6529fa5
Merge current UrbanRecomp main and preserve launcher and engine fixes
mstan Sep 19, 2026
1e8a046
Fix adaptive building roofs using city CHR and whole-cell overlap
mstan Sep 19, 2026
53beb9a
Extend adaptive fax and menu wood from the live tile pattern
mstan Sep 19, 2026
646a180
Keep adaptive title scenery alive through the main-menu fade
mstan Sep 19, 2026
3e470f6
Continue statistics and tax backgrounds without panel-edge smearing
mstan Sep 19, 2026
c9ef8e4
Draw scenario cards and names in the adaptive margins
mstan Sep 19, 2026
d07e9ed
Extend the title light row across the adaptive canvas
mstan Sep 19, 2026
56e90c8
Match adaptive city margins to fine scroll and delayed tile updates
mstan Sep 19, 2026
4059398
Render moving city sprites across the full adaptive margin
mstan Sep 19, 2026
9dd6109
Hold the old adaptive city and palette until load fades finish
mstan Sep 19, 2026
50ad4a5
Respect roof priority and OAM order for adaptive city sprites
mstan Sep 19, 2026
b2f409e
Require actual OpenGL 3.3 and fall back to gameplay without it
mstan Sep 19, 2026
2f57754
Default adaptive controls to a stable top-left position
mstan Sep 19, 2026
5e52ff0
Keep adaptive builds working when the optional launcher is absent
mstan Sep 19, 2026
8294d86
Preserve explicit fullscreen requests when loading launcher settings
mstan Sep 19, 2026
a9cddae
Replace wrapped city edge columns while preserving HUD and sprite pixels
mstan Sep 19, 2026
44e2a21
Document adaptive regression fixes, validation and left-aligned HUD
mstan Sep 19, 2026
0092c05
Center title, menus and advisor pages independently of the city HUD
mstan Sep 19, 2026
dce04b9
Merge main (v1.0.2 and after) into the adaptive renderer
blackerking Sep 22, 2026
06fcbf0
Draw the kept vehicles and the selector's pins and marks in the adapt…
blackerking Sep 22, 2026
3a76afd
Fix three adaptive-renderer faults reported from play
blackerking Sep 22, 2026
d9d20d0
Make the adaptive renderer the default
blackerking Sep 22, 2026
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Thumbs.db
__pycache__/
*.pyc

# Local-only config overrides (per-developer, applied after config.ini)
config.local.ini
sc-video.ini
sc-video.ini.tmp
rom.cfg
# Launcher state (src/sc_launcher.c, recomp-ui)
sc-settings.ini
sc-settings.ini.tmp
Expand Down
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ add_executable(UrbanRecomp
src/sc_selector.c
src/sc_mapgen.c
src/sc_decomp.c
src/sc_video.c
$<$<BOOL:${SC_HAVE_LAUNCHER}>:${CMAKE_SOURCE_DIR}/src/sc_mods.c>
src/sc_renderer.c
)

target_include_directories(UrbanRecomp PRIVATE
Expand Down Expand Up @@ -219,6 +222,32 @@ if(UNIX AND NOT APPLE)
DESTINATION ${CMAKE_INSTALL_DOCDIR})
endif()

include(CTest)
if(BUILD_TESTING)
set(SC_RENDER_TESTS sc_renderer_test)
if(EXISTS "${RECOMP_UI_ROOT}/src/recomp_launcher.h")
add_executable(sc_video_test tests/sc_video_test.c src/sc_video.c src/sc_mods.c)
target_include_directories(sc_video_test PRIVATE src ${RECOMP_UI_ROOT}/src)
add_test(NAME simcity_video COMMAND sc_video_test ${CMAKE_CURRENT_BINARY_DIR}/sc-test-video.ini)
list(APPEND SC_RENDER_TESTS sc_video_test)
endif()
add_executable(sc_renderer_test tests/sc_renderer_test.c src/sc_renderer.c src/sc_video.c
src/sc_selector.c)
target_include_directories(sc_renderer_test PRIVATE src ${SNESRECOMP_RUNNER_INCLUDE_DIRS})
add_test(NAME simcity_renderer COMMAND sc_renderer_test)
foreach(test ${SC_RENDER_TESTS})
if(MSVC)
target_compile_options(${test} PRIVATE /UNDEBUG)
else()
target_compile_options(${test} PRIVATE -UNDEBUG -Wall -Wextra)
target_link_libraries(${test} PRIVATE m)
if(MINGW)
target_link_options(${test} PRIVATE -static)
endif()
endif()
endforeach()
endif()

# ── AOT link probe (step 1 of the CpuState migration) ────────────────────────
#
# Optional target, NOT built by default and NOT part of the shipping
Expand Down Expand Up @@ -374,6 +403,9 @@ if(SC_GEN_SOURCES)
src/sc_decomp.c
src/sc_fiber.c
src/sc_fiberdrive.c
src/sc_video.c
$<$<BOOL:${SC_HAVE_LAUNCHER}>:${CMAKE_SOURCE_DIR}/src/sc_mods.c>
src/sc_renderer.c
${SNESRECOMP_ROOT}/runner/src/cpu_state.c
${SNESRECOMP_ROOT}/runner/src/common_cpu_infra.c
${SNESRECOMP_ROOT}/runner/src/common_rtl.c
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ is simply "the game".
> works -- the launcher lets you pick the file, and the tools recognise it
> by its contents.

**Adaptive Widescreen, the default renderer:** the shared Mods launcher offers
Fit to window, Fit height, Fit width, and 4:3 through 32:9 presets (21:9 out of
the box) while keeping the full original view visible; switching it off there
returns to the classic widescreen. See [build/run instructions and renderer scope](docs/ADAPTIVE_RENDERER.md)
and [the dependency audit](docs/DEPENDENCY_AUDIT.md). The branch retains current
main's engine pin and host fixes; controls default to the top left.

**Just want to build and play it?** See [SETUP.md](SETUP.md) for a
Windows/Linux quick-start. Contributors should read
[CONTRIBUTING.md](CONTRIBUTING.md) instead. For a consolidated map of
Expand Down
249 changes: 249 additions & 0 deletions docs/ADAPTIVE_RENDERER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
# Adaptive Widescreen mod

The built-in **Adaptive Widescreen** mod uses the shared `recomp-ui` Mods
provider, like Super Metroid's custom renderer. Start the executable without
arguments (or with `--mods`), select **Mods**, enable **Adaptive Widescreen**,
choose a view size, and press **Play**. Settings persist in `sc-video.ini`.
Since 2026-09-22 this is Urban Recomp's default renderer: a fresh directory
starts with it enabled at 21:9 (448x224, as wide as the classic widescreen).
Switching it off in Mods (or `Enabled=0` in `sc-video.ini`) returns to the
classic widescreen. New configurations use **Top left** for City controls
position; existing saved Center preferences are respected.

See the [screenshot gallery](screenshots/adaptive-renderer/README.md) for the
Mods controls, adaptive landscape/portrait views, and fixed 21:9 gameplay.

The entire original 256x224 view stays visible in every mode. Terrain and
buildings extend into the extra space; the original controls, text, cursor,
and simulation retain their native coordinates. The original view can be
centered or placed at the top left during gameplay. Top left keeps the toolbar
and status display anchored while added city space grows rightward or downward.
The title, standalone menus and advisor pop-ups stay centered in both modes.
The window is resizable; **F11** toggles
fullscreen. **F10** still opens the game's existing settings menu.

Advisor/tutorial pages move independently of their dimmed city background.
Their native page and portrait pixels are captured from BG3 and the stock
PPU's resolved sprite scanline, then placed at the canvas center. BG1's HUD
and BG2's city remain at the gameplay anchor. The old page's subscreen
occlusion is removed so it leaves no black rectangle behind; transparent
black lettering backed by that occlusion remains part of the opaque page.
Separate budget/statistics, fax, loan and menu screens use a centered view.

| View size | Behavior |
| --- | --- |
| Fit to window | Add columns in a wide window or rows in a tall window |
| Fit height | Keep 224 rows; add columns when the window is wide enough |
| Fit width | Keep 256 columns; add rows when the window is tall enough |
| 4:3 | Original view, corrected pixel aspect |
| 8:7 | Original view, square pixels |
| 16:10 | 308x224 canvas |
| 16:9 | 342x224 canvas |
| 21:9 | 448x224 canvas |
| 32:9 | 684x224 canvas |

Fit height/width add bars where filling the other axis would crop the original
view. Fixed presets also use bars when the window has a different aspect.
Logical pixels use a 7:6 pixel aspect for 4:3 SNES presentation, except 8:7.
Canvas dimensions round outward to even pixels, so some ratios have a tiny
rounding border. Each axis caps at 2048 logical pixels; extreme windows use
bars after reaching that cap. Scaling preserves proportions.

## Build and run

Initialize both shared dependencies, including their nested submodules:

```sh
git submodule update --init --recursive
```

On Windows with CMake, MinGW-w64, Ninja and SDL3 installed under
`C:/msys64/mingw64`, run from PowerShell:

```powershell
.\tools\run_custom_renderer.ps1 -Rom 'C:\Roms\SimCity (USA).sfc'
```

`-BuildOnly` builds without opening a window; `-SkipBuild` starts an existing
build. `-CMake` and `-Toolchain` override the executable and MinGW paths.
The script runs from this checkout so its settings, saves and optional Sylt
assets stay local to it. On other platforms, use CMake's native generator:

```sh
cmake -S . -B build-custom -DCMAKE_BUILD_TYPE=Release
cmake --build build-custom --parallel
ctest --test-dir build-custom --output-on-failure
./build-custom/UrbanRecomp /path/to/simcity.sfc --mods
```

No code generation is needed for the default executable. See
[the dependency audit](DEPENDENCY_AUDIT.md) before using the experimental AOT
targets with the updated engine.

Direct launch examples (CLI overrides last for that launch; Play in the Mods
launcher persists settings):

```sh
UrbanRecomp simcity.sfc --widescreen --aspect Fit --window-size 1280x720
UrbanRecomp simcity.sfc --widescreen --aspect Width --window-size 720x1280
UrbanRecomp simcity.sfc --widescreen --aspect 32:9 --fullscreen
UrbanRecomp simcity.sfc --no-widescreen
```

`--video-config FILE` selects an isolated settings file. Supported CLI aspect
names are `Fit`, `Height`, `Width`, `4:3`, `8:7`, `16:10`, `16:9`, `21:9`, `32:9`.

## Renderer scope

The city reconstruction is for the verified unheadered USA ROM, SHA-256
`e9c0bc05511e05a0d7c3e7cc42e761e1e8e532d46f59b9854b6902e1a2e9dd0a`.
It reads the 120x100 live map at WRAM offset `0x10200`, ROM tile tables at
`0x156a9` and `0x14f2d`, and current PPU CHR, palette and brightness at each
scanline. Roof tiles share BG2 graphics and overlap one whole cell (8 pixels)
up and left. Fine scrolling follows the PPU, including delayed coarse-cell
updates. The outer eight columns of the original city tilemap are CRT
overscan staging space; they are reconstructed from the world map when widened.
Rows with HUD or native sprite content in an edge band retain those pixels.
World bounds show the backdrop. Taller views use the first/last scanline's
PPU state beyond the hardware's vertical range.

Title scenery, main-menu and scenario-selector wood, fax desk and advisor backdrop also extend.
Other menus retain their native contents over repeated background decoration
or the backdrop. Menu content is not spread across an ultrawide display.
Interactions stay within the original game's view. Moving game-emitted sprites
continue through the adaptive margins with OAM priority, palette and tile flips;
parked HUD copies are rejected. The renderer does not create simulation actors
that the guest has not emitted, or extrapolate movement after the guest hides them. Pan normally to interact with a place
first seen in a margin. Other ROM regions and all disaster scenes have not
been qualified for custom rendering.

The renderer never writes WRAM, VRAM, OAM or CGRAM. Native pixels are
copied byte-for-byte except for the city's bare eight-pixel staging columns
and the background revealed when relocating an advisor page. The relocated
page retains its finished native pixels. HUD and sprite pixels remain intact.
It uses its own dynamic
surface, independently of the shared PPU's horizontal widening limit. While
the mod is enabled it supersedes legacy `SC_WIDESCREEN` / `SC_HOST_MAP` paths.
Existing game fixes still run identically with the mod enabled and disabled.

## Validation

ROM-free CTests cover full-view containment, extreme windows, scaling/input
coordinates, all Mods choices, toggle/persistence, tile flips, transparent
overlap, map bounds, PPU immutability, desk periods, title fades/lights,
scenario cards, flat-menu fills, fine/coarse scroll handoff, sprite crossings
and priority, city-load holding, and staging-edge repairs that preserve HUD.
Layout checks also cover independent panel placement, black lettering and
sprite pixels, the old panel's subscreen window, fades and returning to play.

With Python and Pillow, the integration test runs normal inputs through boot,
main menu, scenario selector, populated San Francisco, fax, advisor and a practice city. It checks every frame's CPU,
WRAM and master clock with the mod on/off, and compares the native view
byte-for-byte in periodic captures outside explicitly reported staging-edge
repairs. Each adaptive capture has an audit JSON listing exactly which
eight-pixel bands were corrected on each row. It then pans through all presets, wide,
square and portrait Fit modes, plus top-left positioning.

```sh
python tools/test_adaptive_renderer.py --exe build-custom/UrbanRecomp.exe --rom simcity.sfc --artifacts build-custom/integration
```

The test prints a fresh artifact directory containing logs, PPMs, PNG previews
and a local `stock-route/city.state`. Use that state for the Windows resize
test; it owns and closes only its child process/window:

```sh
python tools/test_adaptive_window.py --exe build-custom/UrbanRecomp.exe --rom simcity.sfc --state ARTIFACTS/stock-route/city.state --artifacts build-custom/integration
```

The independent layout regression checks both wide and portrait windows:

```sh
python tools/test_adaptive_layout.py --exe build-custom/UrbanRecomp.exe --rom simcity.sfc --artifacts build-custom/integration
```

It verifies centered title/menu/fax pages, left gameplay controls, and centered
advisor pages without moving their city/HUD background. A stock-PPU reference
pass hides the foreground and removes the obsolete subscreen occlusion using
`SC_LAYER_MASK=3 SC_SUB_WINDOW_MASK=0`. The latter diagnostic override is
restored immediately after drawing, before guest execution resumes. The
revealed background must match that reference; relocated page pixels must
match the original stock picture. All four runs retain identical guest state.
Audit captures include the relocated page mask. Review the resulting images
as well as the numerical checks.

The resize test covers 16:9, 21:9, 32:9, portrait, square and 4:3 window shapes.
`--screenshots` additionally brings its child forward for desktop screenshots;
the default test does not request foreground focus. Live keyboard/mouse input
is ignored in this scripted test so typing elsewhere cannot change the city.
Review the canvas images for new-world correctness in addition to the
automated size and native-view checks. Pixel equality alone does not establish
that newly exposed scenery is correct.

`tools/test_adaptive_launcher.py` accepts the same arguments as the resize
test. It clicks the actual Mods toggle and 32:9 choice, presses Play, then
checks the persisted settings and launched canvas.

The new local save format preserves PPU CPU-port latches, the host clock and
HDMA walker in addition to the shared machine snapshot. The old unversioned
format omitted those latches: loading it shifted later tile uploads and
corrupted water/shore graphics even with the mod disabled. Current main accepts legacy states with a warning; they still lack those
latches. Use fresh versioned states for rendering comparisons. The regression compares a 300-frame
restore against uninterrupted play, including captured pixels. In-game SRAM
city saves are separate from these local emulator snapshots.


## Regression follow-up (2026-09-19)

The developer's [eleven-item checklist](https://github.com/blackerking/UrbanRecomp/issues/2)
was caused by two gaps: the draft predates main's newer host fixes, and its
separate margin renderer did not inherit the classic renderer's screen-specific
handling. The original tests compared guest state and the native rectangle;
they could pass while the newly exposed picture was wrong. The roof fixture
also encoded a one-pixel offset instead of the format's one-cell offset.

Current main `28c280b` is merged. Its published engine pin `bc2838d`, beam and
audio fixes, translations, SRAM persistence and guarded launcher are retained.
Sylt and Adaptive Widescreen share that launcher. A shared-engine migration is
separate work; this branch no longer drops the game's engine dependencies.

| Report | Resolution |
| --- | --- |
| 1. Title lights | Repeat the detected live OAM light row across the canvas |
| 2. Title fade | Keep title scenery while screen 2 fades; obey live brightness and force blank |
| 3. Scenario cards | Render the actual wide card/name maps once, extend wood outside them |
| 4. Fax | Detect the desk layer and its real 16-column/vertical pattern |
| 5. Scroll seam | Follow fine/coarse scroll and reconstruct the bare staging-edge columns |
| 6. Roofs | Use BG2 graphics and an eight-pixel overlap |
| 7. Moving objects | Decode moving OAM across the canvas, with priority and parked-slot rejection |
| 8. Statistics/tax margins | Use the majority native background, avoiding panel/cursor stripes |
| 9. City load | Hold old map, graphics, palette and camera through dark-to-lit transition |
| 10. No OpenGL | Probe the actual GL version; skip the launcher below desktop GL 3.3 |
| 11. Engine pin | Retain current main's published engine and optional AOT ABI |

Validation uses the expanded CTests, the 16-case game-route suite, six actual
window resizes, actual Mods toggle/choice/Play/persistence, and a no-OpenGL run
using SDL's dummy video/software renderer. A build with the launcher dependency
absent is also checked. AOT and every translated/disaster sequence are not
qualified by these tests. The moving-object regression exercises native OAM
crossings; it does not claim arbitrary offscreen simulation objects exist.

Top-left is the default HUD layout because its controls stay together and the
extra map gets a stable origin. Center remains available under City controls
position. Title/menu centering is independent of that setting. Advisor pages
are separated from the composed picture as described above, so opening a page
does not move the city or toolbar.


The final renderer run (`a9cddae`) completed 13,920 paired CPU/WRAM/clock frame
checks and 142 native-region captures across 16 cases, plus the separate
300-frame save/restore comparison. Capture audits identify the corrected
overscan bands; all other native pixels must match. The final six-window
resize run and screenshots include the left-aligned default. See the
[updated gallery](screenshots/adaptive-renderer/README.md).

The independent-centering follow-up also passes 7,200 paired guest-state
checks and 48 layout captures, including eight advisor captures checked
against the stock page and unoccluded-background references. Both city and
advisor states pass the six actual window-resize shapes. The gallery includes
the centered title, main menu and wide/portrait advisor pages.
59 changes: 59 additions & 0 deletions docs/DEPENDENCY_AUDIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
> Update after integrating UrbanRecomp main `28c280b` (2026-09-19): the branch
> now retains the game's published `blackerking/snesrecomp` pin `bc2838d`.
> Its PPU fixes and optional AOT ABI are dependencies of current main. The old
> shared-main migration below is historical, not the current build contract.
> The host now uses main's master-clock charge hook instead of the draft's
> deferred DMA shim. Both Sylt and Adaptive Widescreen use main's launcher,
> including its no-OpenGL fallback, translations, key bindings and SRAM saves.

# Shared dependency audit

This branch starts from SimCitySNESRecomp upstream `master` at `d54bbbd`
and updates the `snesrecomp` gitlink from `a6a037f` to shared `main` at
`4d42cab`. The engine source is unmodified. `recomp-ui` is added at
`cb7e54b` for the same built-in Mods provider used by Super Metroid.

The old engine URL, `https://github.com/mstan/snesrecomp.git`, is the shared
repository, not a game-owned fork URL. Its pinned history nevertheless contains
six commits outside current shared main:

| Commit | Change |
| --- | --- |
| `0183d9a` | Treat COP as a tier-to-LLE call instead of structural poison |
| `3dbd292` | Add `exit_mx_set` for callees returning in multiple M/X widths |
| `93d4dd1` | Diagnostics for interpreter bridge runs that never return |
| `2a095a1` | Opcode trace markers and an APU diagnostic switch |
| `2c06601` | Deadline reporting at the firing point |
| `a6a037f` | Return a deadline unwind to the host |

This is divergent dependency history despite using the shared repository URL.
The current engine already handles deadline unwinds, but the old COP analysis
and `exit_mx_set` behavior should not be assumed to have landed. In current
Python analysis, BRK/COP still receive structural-poison treatment. The game
configs use `exit_mx_set` in banks 00, 01 and 02; current config parsing does
not implement that directive.

The default game executable is the standalone LLE interpreter host. It does
not compile generated banks or use those directives, so it can run the latest
engine without keeping a private engine patch. This branch adapts its host
to the current shared API: links S-DD1 device support, supplies the device
layer's DMA cycle accumulator, applies charged DMA time through the host's
existing beam loop, holds the shared beam during writes to avoid a second
HDMA/clock owner, and uses the shared SDL3 keyboard adapter.

The experimental AOT targets and `tools/regen.sh` require a separate migration
of the COP/width analysis assumptions before their old qualification claims
can be repeated against this pin. They are not part of this renderer's
validated build. Preserve the six commits as review references; do not remove
the width annotations merely to make regeneration accept the configs.

Reproduce the history check from this checkout:

```sh
git -C snesrecomp remote -v
git -C snesrecomp log --oneline 4d42cab..a6a037f
git -C snesrecomp status --short
git submodule status
```

Build and validation instructions are in [ADAPTIVE_RENDERER.md](ADAPTIVE_RENDERER.md).
Loading