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
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(RECOMP_UI_ROOT "${CMAKE_SOURCE_DIR}/recomp-ui" CACHE PATH
"Path to the recomp-ui checkout used by this game")
include(${RECOMP_UI_ROOT}/recomp_ui.cmake)


find_package(OpenGL REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter)

Expand Down Expand Up @@ -314,3 +315,21 @@ execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${SNESRECOMP_ROOT}
set_property(SOURCE src/smw_replay.c APPEND PROPERTY COMPILE_DEFINITIONS
SMW_REPLAY_REVISION="${SMW_REPLAY_REVISION}" SMW_REPLAY_ENGINE="${SMW_REPLAY_ENGINE}"
SMW_REPLAY_TARGET="${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}-${CMAKE_BUILD_TYPE}")

add_executable(smw-controller-report
"${RECOMP_UI_ROOT}/tools/input_report.c"
"${RECOMP_UI_ROOT}/src/common/launcher_input_report.c")
target_include_directories(smw-controller-report PRIVATE
"${RECOMP_UI_ROOT}/src" "${RECOMP_UI_ROOT}/src/common")
target_compile_definitions(smw-controller-report PRIVATE SDL_MAIN_HANDLED=1)
if(SNESRECOMP_SDL_BACKEND STREQUAL "SDL3" AND TARGET SDL3::SDL3)
target_compile_definitions(smw-controller-report PRIVATE LNG_SDL3=1)
target_link_libraries(smw-controller-report PRIVATE SDL3::SDL3)
elseif(TARGET SDL2::SDL2)
target_link_libraries(smw-controller-report PRIVATE SDL2::SDL2)
else()
message(FATAL_ERROR "Controller reporting requires the configured SDL target")
endif()
if(MINGW)
target_link_options(smw-controller-report PRIVATE -static)
endif()
17 changes: 17 additions & 0 deletions CONTROLLER_DIAGNOSTICS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Controller detection reports

Connect the controller, then run `Collect-Controller-Diagnostics.cmd` from the
extracted download. Press and release its buttons, move both sticks and use the
D-pad during the first capture. The launcher then opens for a second capture:
check its controller list and bindings, then close it. You do not need to select
a ROM or save file, or start gameplay.

The helper prints the path to a ZIP containing the device and launcher reports.
Attach it to your issue and say whether Windows lists the controller as a game
controller. Reports include raw USB joystick identities, SDL mapping status,
button/axis/hat events, selected player devices, bindings and build hashes.
They do not include your ROM or save files and do not upload automatically.
Review the reports before sharing them.

Reports normally live in `diagnostics` beside the game. If that folder cannot be
written, the helper uses `%LOCALAPPDATA%\SuperMarioWorldRecomp\diagnostics`.
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SkipLauncher = 0

[Graphics]
# Window size ( Auto or WidthxHeight )
WindowSize = Auto
WindowSize = 1280x720

# Fullscreen mode (0=windowed, 1=desktop fullscreen, 2=fullscreen w/mode change)
Fullscreen = 0
Expand Down
2 changes: 1 addition & 1 deletion recomp-ui
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3185,7 +3185,7 @@ static const char kDefaultConfigIniContent[] =
"\n"
"[Graphics]\n"
"# Window size (Auto or WidthxHeight)\n"
"WindowSize = Auto\n"
"WindowSize = 1280x720\n"
"\n"
"# Fullscreen mode (0=windowed, 1=desktop fullscreen, 2=fullscreen w/mode change)\n"
"Fullscreen = 0\n"
Expand Down
28 changes: 27 additions & 1 deletion src/smw_renderer_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ static unsigned r16(CpuState *c,unsigned a) { return r8(c,a)|(r8(c,a+1)<<8); }
static bool active(CpuState *c) {
return g_smw_video.enabled && g_smw_viewport.width>256 && r8(c,0x100)==0x14;
}
static bool shooter_tail(CpuState *c) {
return g_smw_video.adaptive_spawns && g_smw_viewport.extra &&
active(c) && !(r8(c,0x5b)&1);
}
/* The generated loader uses the same policy as its interpreted counterpart.
* Optional existing spawn diagnostics distinguish actual execution tiers. */
int SmwRendererShooterTail(CpuState *c) {
if(!shooter_tail(c)) return 0;
spawn_event(c,"shooter-tail-aot",c->X&255,c->A&255,r16(c,c->D));
return 1;
}
static int left_margin(CpuState *c) {
return r8(c,0x5b)&1 ? g_smw_viewport.extra :
SmwViewOffset(g_smw_viewport,r16(c,0x1a),(r8(c,0x5e)+1)*256);
Expand Down Expand Up @@ -145,6 +156,21 @@ void SmwRendererGuestHook(CpuState *c,uint32_t pc) {
SmwRendererEndActor();
return;
}
if(pc==0x02A8D8) {
/* The shooter factory ends with JMP LoadSpriteLoopStrt, not RTS. The
* native frontier normally bounds that continuation. Our full-list sweep
* can instead reach the terminator inside the factory; a nested JSR then
* returns to LoadNextSprite beyond that terminator and wraps the list.
* Enter the factory as the tail continuation it already implements, so
* the list's eventual RTS returns directly to the loader's caller.
* This hook runs before the interpreted JSR pushes anything; generated
* callers apply the same policy with the ordinary tail-return ABI. */
if(shooter_tail(c)) {
spawn_event(c,"shooter-tail-interp",c->X&255,c->A&255,r16(c,c->D));
interp_bridge_pre_opcode_redirect(((uint32_t)c->PB<<16)|0xab78u);
}
return;
}
if(!active(c)) return;
if(pc==0x01F76C) {
/* A waiting placed egg uses IsSprOffScreen before its native proximity
Expand Down Expand Up @@ -388,7 +414,7 @@ void SmwRendererGuestHook(CpuState *c,uint32_t pc) {
}
}
void SmwRendererInstallHooks(void) {
const uint32_t pcs[]={0x02A826,0x02A82E,0x01B844,0x01AC7C,0x02D076,0x03B8A8,0x02A1BE,0x02A204,
const uint32_t pcs[]={0x02A826,0x02A82E,0x02A8D8,0x01B844,0x01AC7C,0x02D076,0x03B8A8,0x02A1BE,0x02A204,
0x019E6D,0x019E93,0x019F5A,0x0180E5,0x02A916,0x02AFB3,
0x01A393,0x02D3A6,0x03B78E,
0x0180AF,0x0180B2,0x029B0C,0x029B12,0x02A27E,0x02A2BE,
Expand Down
26 changes: 25 additions & 1 deletion test/renderer/renderer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ uint8 cpu_read8(CpuState *cpu,uint8 bank,uint16 addr) {
}
void cpu_write8(CpuState *cpu,uint8 bank,uint16 addr,uint8 value) { (void)cpu; assert(bank==0x7e); g_ram[addr]=value; }
void interp_bridge_set_pre_opcode_hook(uint32_t pc,InterpPreOpcodeHook hook) { (void)pc;(void)hook; }
static uint32_t redirected_pc;
void interp_bridge_pre_opcode_redirect(uint32_t pc) { redirected_pc=pc; }
extern void SmwRendererGuestHook(CpuState *,uint32_t);
extern void SmwRendererDrawInfo(CpuState *);
static void word(unsigned a,unsigned value) { g_ram[a]=value;g_ram[a+1]=value>>8; }
Expand Down Expand Up @@ -99,6 +101,28 @@ static void spawn(void) {
assert(g_ram[0x15c4]==1 && cpu._flag_Z==0);
}
}
static void shooter_continuation(void) {
CpuState cpu={0};cpu.PB=2;cpu.S=0x1f5;cpu.A=0xca;cpu.X=16;cpu.Y=50;
memset(g_ram,0,sizeof(g_ram));g_ram[0x100]=20;
g_smw_video=(SmwVideoSettings){true,true,0};g_smw_viewport=(SmwViewport){308,26,1.6};
/* A shooter is a continuation of this sweep, not a nested full-list scan.
* Its final JMP must eventually return through the existing loader frame. */
redirected_pc=0;SmwRendererGuestHook(&cpu,0x02A8D8);
assert(redirected_pc==0x02ab78 && cpu.S==0x1f5);
assert(cpu.A==0xca && cpu.X==16 && cpu.Y==50 && !g_ram[0x100+1]);
cpu.PB=0x82;redirected_pc=0;SmwRendererGuestHook(&cpu,0x82A8D8);
assert(redirected_pc==0x82ab78); /* retain the executing ROM mirror */
for(int mode=0;mode<5;++mode) {
g_smw_video=(SmwVideoSettings){true,true,0};g_smw_viewport=(SmwViewport){308,26,1.6};
g_ram[0x100]=20;g_ram[0x5b]=0;
if(mode==0)g_smw_video.adaptive_spawns=false;
if(mode==1)g_smw_video.enabled=false;
if(mode==2)g_smw_viewport.width=256,g_smw_viewport.extra=0;
if(mode==3)g_ram[0x5b]=1; /* vertical uses the original frontier */
if(mode==4)g_ram[0x100]=0x13;
redirected_pc=0;SmwRendererGuestHook(&cpu,0x02A8D8);assert(!redirected_pc);
}
}
typedef struct StateBuffer { SaveLoadInfo base; bool writing; size_t position; uint8_t data[256]; } StateBuffer;
static void state_transfer(SaveLoadInfo *sli,void *data,size_t size) {
StateBuffer *buffer=(StateBuffer *)sli;
Expand Down Expand Up @@ -616,4 +640,4 @@ static void raster_storage(void) {
(y==2 || y==3?0x00ff00u:0xff0000u));
SmwRendererResetScene();
}
int main(void) { geometry();spawn();spawn_lifecycle();ghost_house_capacity();objects();sprite_parts();completed_draws();transitions();map16();pipe_variants();hud();parallax();camera_timing();raster_storage();puts("geometry, spawn lifecycle/save state and ghost-house capacity, signed OAM/sprite parts, independent sprite draws, transitions, Map16/pipe variants, anchored HUD, parallax, presentation camera timing and immutable VRAM raster storage: passed");return 0; }
int main(void) { geometry();spawn();shooter_continuation();spawn_lifecycle();ghost_house_capacity();objects();sprite_parts();completed_draws();transitions();map16();pipe_variants();hud();parallax();camera_timing();raster_storage();puts("geometry, shooter continuation, spawn lifecycle/save state and ghost-house capacity, signed OAM/sprite parts, independent sprite draws, transitions, Map16/pipe variants, anchored HUD, parallax, presentation camera timing and immutable VRAM raster storage: passed");return 0; }
4 changes: 4 additions & 0 deletions tools/Collect-Controller-Diagnostics.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
cd /d "%~dp0"
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0Collect-Controller-Diagnostics.ps1"
pause
81 changes: 81 additions & 0 deletions tools/Collect-Controller-Diagnostics.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
param([switch]$NoLauncher, [ValidateRange(100,30000)][int]$DurationMs=10000)
$ErrorActionPreference='Stop'
$root=$PSScriptRoot
$game=Join-Path $root 'SuperMarioWorldSNESRecomp.exe'
$helper=Join-Path $root 'smw-controller-report.exe'
$folder=Join-Path $root 'diagnostics'
try {
New-Item -ItemType Directory -Path $folder -Force -ErrorAction Stop | Out-Null
$probe=Join-Path $folder ('.controller-write-'+[guid]::NewGuid().ToString('N')+'.tmp')
$stream=[IO.File]::Open($probe,[IO.FileMode]::CreateNew,[IO.FileAccess]::Write)
$stream.Dispose()
Remove-Item -LiteralPath $probe -ErrorAction Stop
}
catch {
$folder=Join-Path $env:LOCALAPPDATA 'SuperMarioWorldRecomp\diagnostics'
New-Item -ItemType Directory -Path $folder -Force | Out-Null
}
$stamp=(Get-Date).ToUniversalTime().ToString('yyyyMMdd-HHmmss-fff')+'-'+$PID
$raw=Join-Path $folder ('controller-'+$stamp+'-devices.jsonl')
$launcher=Join-Path $folder ('controller-'+$stamp+'-launcher.jsonl')
$identity=Join-Path $folder ('controller-'+$stamp+'-build.txt')
$windows=Join-Path $folder ('controller-'+$stamp+'-windows.json')
$zip=Join-Path $folder ('controller-'+$stamp+'.zip')
foreach ($file in $helper,$game) {
if (-not (Test-Path -LiteralPath $file -PathType Leaf)) { throw "Missing $file. Extract the complete download first." }
}
$lines=@('Super Mario World controller report')
foreach ($file in $helper,$game) {
$lines+=([IO.Path]::GetFileName($file)+' SHA256='+ (Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash)
}
[IO.File]::WriteAllLines($identity,$lines,(New-Object Text.UTF8Encoding($false)))
$deviceRows=@()
$queryStatus='success'
try {
$devices=Get-CimInstance Win32_PnPEntity -Filter "PNPClass='HIDClass' OR PNPClass='USB' OR PNPClass='XnaComposite'"
foreach ($device in $devices) {
if ($device.DeviceID -match 'VID_([0-9A-F]{4}).*PID_([0-9A-F]{4})') {
$deviceRows+=[pscustomobject]@{
name=$device.Name; vendor=$Matches[1]; product=$Matches[2]
class=$device.PNPClass; service=$device.Service; status=$device.Status
errorCode=$device.ConfigManagerErrorCode
}
}
}
} catch { $queryStatus='failed: '+$_.Exception.Message }
$windowsReport=[pscustomobject]@{
query=$queryStatus; count=$deviceRows.Count; truncated=($deviceRows.Count -gt 256)
devices=@($deviceRows | Select-Object -First 256)
}
[IO.File]::WriteAllText($windows,($windowsReport | ConvertTo-Json -Depth 5),(New-Object Text.UTF8Encoding($false)))
Write-Output 'Connect the controller. During this capture, press/release buttons and move the sticks and D-pad.'
$start=New-Object Diagnostics.ProcessStartInfo
$start.FileName=$helper
$start.Arguments='"'+$raw+'" '+$DurationMs
$start.WorkingDirectory=$root
$start.UseShellExecute=$false
$start.CreateNoWindow=$true
$process=[Diagnostics.Process]::Start($start)
try { $process.WaitForExit(); if ($process.ExitCode) { throw 'Controller capture failed.' } }
finally { $process.Dispose() }
if (-not $NoLauncher) {
$oldReport=$env:RECOMP_INPUT_REPORT
$oldDuration=$env:RECOMP_INPUT_REPORT_MS
try {
$env:RECOMP_INPUT_REPORT=$launcher
$env:RECOMP_INPUT_REPORT_MS='30000'
Write-Output 'The launcher will open. Check the controller list and bindings, then close it. No ROM or save-file selection is needed.'
$start=New-Object Diagnostics.ProcessStartInfo
$start.FileName=$game
$start.WorkingDirectory=$root
$start.UseShellExecute=$false
$process=[Diagnostics.Process]::Start($start)
try { $process.WaitForExit() } finally { $process.Dispose() }
} finally {
$env:RECOMP_INPUT_REPORT=$oldReport
$env:RECOMP_INPUT_REPORT_MS=$oldDuration
}
}
$files=@($raw,$launcher,$identity,$windows) | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf }
Compress-Archive -LiteralPath $files -DestinationPath $zip
Write-Output "Report ready: $zip"
22 changes: 21 additions & 1 deletion tools/apply_renderer_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ def apply(text):
m = re.search(r'cpu_trace_block\(cpu, 0x([0-9A-F]+)\)', line)
if m: block = m[1]
hook = None
if block == '02A8D8' and 'cpu_trace_block' in line:
# LoadShooter tail-jumps into this list loop. An adaptive full-list
# sweep must not leave a nested JSR frame that resumes past its
# terminator. Match the interpreter hook without changing native
# allocation or reducing generated execution coverage.
if name == 'SprXXX_LoadShooter_M1X1':
tail = 'goto L_AB78_M1X1;'
elif name in ('ParseLevelSpriteList_M1X1', 'ParseLevelSpriteList_Entry2_M1X1'):
tail = ('extern RecompReturn SprXXX_LoadShooter_M1X1(CpuState *); '
'cpu->host_return_valid = _hrv; '
'cpu_tailcall_inherit_return_context(_entry_s, _hrv); '
'RecompReturn _tc = SprXXX_LoadShooter_M1X1(cpu); '
'RecompStackPop(); return _tc;')
else:
raise SystemExit(f'Unsupported shooter continuation owner: {name}')
out.append(line)
out.append(' /*SMW-HOST*/ { extern int SmwRendererShooterTail(CpuState *); '
f'if (SmwRendererShooterTail(cpu)) {{ {tail} }} }}\n')
found.add('shooter_tail')
continue
if block == '01A7EB' and 'if (cpu->_flag_Z == 1)' in line and '$A7F7' in line:
out.append(' /*SMW-HOST*/ { extern void SmwRendererGuestHook(CpuState *, uint32_t); SmwRendererGuestHook(cpu, 0x01A7F3u); }\n')
found.add('player_contact')
Expand Down Expand Up @@ -79,7 +99,7 @@ def main():
changed, hits = apply(text)
found |= hits
if changed != text: updates.append((path, changed))
missing = set(PCS) | {'draw', 'fireball', 'frontier', 'wing_cull', 'sprite_allocation', 'baseball_cull', 'player_cull', 'player_contact'}
missing = set(PCS) | {'draw', 'fireball', 'frontier', 'wing_cull', 'sprite_allocation', 'baseball_cull', 'player_cull', 'player_contact', 'shooter_tail'}
missing -= found
if missing: raise SystemExit(f'Missing required renderer hook sites: {missing}')
for path, changed in updates: path.write_text(changed, encoding='utf-8', newline='\n')
Expand Down
25 changes: 17 additions & 8 deletions tools/make_release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ if (-not $stageFull.StartsWith($outFull, [StringComparison]::OrdinalIgnoreCase)
}

if (Test-Path -LiteralPath $stage) {
Remove-Item -LiteralPath $stage -Recurse -Force
$contents = @(Get-Item -LiteralPath $stage) + @(Get-ChildItem -LiteralPath $stage -Recurse)
if ($contents | Where-Object { ($_.Attributes -band [IO.FileAttributes]::ReparsePoint) -or $_.Name -eq '.git' }) {
throw 'Refusing staging cleanup with a reparse point or nested repository.'
}
Remove-Item -LiteralPath $stage -Recurse -ErrorAction Stop
}
if (Test-Path -LiteralPath $zip) {
Remove-Item -LiteralPath $zip -Force
Remove-Item -LiteralPath $zip -ErrorAction Stop
}
New-Item -ItemType Directory -Path $stage -Force | Out-Null

Expand All @@ -113,6 +117,15 @@ if ($Variant -eq 'coop') {
Copy-Item -LiteralPath (Join-Path $root 'recomp\coop\smw_coop.ips') -Destination $stage
}
Copy-Item -LiteralPath (Join-Path $root 'README.md') -Destination $stage
if ($Variant -eq 'stock') {
$controllerHelper = Join-Path $build 'smw-controller-report.exe'
if (-not (Test-Path -LiteralPath $controllerHelper)) { throw 'Build smw-controller-report before packaging.' }
Copy-Item -LiteralPath $controllerHelper -Destination $stage
foreach ($file in 'Collect-Controller-Diagnostics.cmd','Collect-Controller-Diagnostics.ps1') {
Copy-Item -LiteralPath (Join-Path $root ('tools/'+$file)) -Destination $stage
}
Copy-Item -LiteralPath (Join-Path $root 'CONTROLLER_DIAGNOSTICS.md') -Destination $stage
}
Copy-Item -LiteralPath $assets -Destination $stage -Recurse
$luaEnabled = Select-String -LiteralPath (Join-Path $build 'CMakeCache.txt') `
-Pattern '^SNESRECOMP_ENABLE_LUA:BOOL=ON$' -Quiet
Expand All @@ -135,12 +148,8 @@ $stageMods = Join-Path $stage 'mods'
New-Item -ItemType Directory -Path $stageMods -Force | Out-Null
Copy-Item -LiteralPath (Join-Path $mods 'preloaded') -Destination $stageMods -Recurse

# keybinds.ini is auto-generated next to the exe on first run (regenerated if
# deleted); ship whatever is currently sitting next to the built exe, if any.
$kb = Join-Path $build 'keybinds.ini'
if (Test-Path -LiteralPath $kb) {
Copy-Item -LiteralPath $kb -Destination $stage
}
# Generate fresh bindings on first run. Do not ship a developer's device
# assignments or overwrite an existing player's binding file during updates.

# config.ini ships Widescreen = 0 regardless of the repo's working-tree value
# (a dev may have flipped it locally while testing); the launcher toggles +
Expand Down
11 changes: 11 additions & 0 deletions tools/test_adaptive_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ def main():
assert 'wing_cull' in hits and patched.count('SmwRendererGuestHook(cpu, 0x019E6Du)')==1
_,hits=hooks.apply(' cpu_trace_block(cpu, 0x019E3C);\n if (cpu->_flag_Z == 0) { goto L_OTHER; }\n')
assert 'wing_cull' not in hits
for name in ('ParseLevelSpriteList_M1X1', 'ParseLevelSpriteList_Entry2_M1X1', 'SprXXX_LoadShooter_M1X1'):
source=f'RecompReturn {name}(CpuState *cpu) {{\n cpu_trace_block(cpu, 0x02A8D8);\n'
patched,hits=hooks.apply(source)
assert 'shooter_tail' in hits and patched.count('SmwRendererShooterTail(cpu)')==1
if name.startswith('Parse'):
assert 'cpu_tailcall_inherit_return_context(_entry_s, _hrv)' in patched
assert 'RecompStackPop(); return _tc;' in patched
else:
assert 'goto L_AB78_M1X1;' in patched
assert 'cpu_tailcall_inherit_return_context' not in patched
assert hooks.apply(patched)[0]==patched
for path in (ROOT/'src/gen').glob('*.c'):
a,_=hooks.apply(path.read_text());b,_=hooks.apply(a)
assert a==b,path
Expand Down
Loading