@echo off
setlocal enabledelayedexpansion
set "WS=%~1"
if "%WS%"=="" set "WS=D:\vscode-workspace\xbox-dvd-tools-v2"
set "HERE=%~dp0"
set "PY=python"
where python >nul 2>nul || set "PY=C:\Python312\python.exe"
set "FW=%WS%\firmware\GDR-8050L\8050L_fw_plaintext_256k.bin"

echo [RUN] v109 0x0729 route sweep with fixed READ CAPACITY CDB 0x25.
echo [RUN] This overrides only the read of 0x0729 at PC 0x9001DF69.
for %%I in (0 1 2 3 4 5 6 7 8 9 A B C D E F) do (
  set "OUT=gdr8050l_readcap_route_0729_%%I_v109_trace.csv"
  echo [RUN] 0x0729=0x%%I out=!OUT!
  "%PY%" "%HERE%run_direct_firmware.py" ^
    --workspace "%WS%" ^
    --bin "%FW%" ^
    --base 0x90000000 ^
    --entry 0x90000020 ^
    --model GDR-8050L ^
    --name "GDR-8050L v109 READ CAPACITY route sweep 0729=0x%%I" ^
    --max-cycles 90000 ^
    --sp 0x003FF000 ^
    --preset gdr8050l-packet-full-cdb ^
    --clear-preset-stops ^
    --packet-cdb 0x25 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ^
    --packet-data-in 0x00 0x34 0x5B 0x5F 0x00 0x00 0x08 0x00 ^
    --read8 0x00000729@0x9001DF69=0x%%I ^
    --mem8 0x0003E7BA=0x01 ^
    --mem8 0x0003E7BB=0x01 ^
    --mem8 0x0003E7BC=0x00 ^
    --mem8 0x0003E7BD=0x06 ^
    --mem8 0x0003E7BE=0x06 ^
    --mem8 0x0003E7BF=0x00 ^
    --breakpoint 0x9001DF69 ^
    --breakpoint 0x9001DF75 ^
    --breakpoint 0x9001DF7A ^
    --breakpoint 0x9001DF7C ^
    --breakpoint 0x9001E301 ^
    --breakpoint 0x9001E303 ^
    --breakpoint 0x9001E55C ^
    --breakpoint 0x9001E55E ^
    --breakpoint 0x9001E614 ^
    --breakpoint 0x9001E65F ^
    --breakpoint 0x9001E696 ^
    --breakpoint 0x9001E72A ^
    --breakpoint 0x9001E779 ^
    --breakpoint 0x9001E84D ^
    --breakpoint 0x9001E883 ^
    --breakpoint 0x9001F02E ^
    --breakpoint 0x9001F030 ^
    --breakpoint 0x9001F216 ^
    --breakpoint 0x900397B4 ^
    --breakpoint 0x900396FD ^
    --breakpoint 0x9003971A ^
    --breakpoint 0x90039767 ^
    --breakpoint 0x90039778 ^
    --watchpoint 0x00000729:1@access ^
    --watchpoint 0x0003E7BA:8@access ^
    --watchpoint 0x8003E7BA:8@access ^
    --trace-csv "%HERE%!OUT!" ^
    --trace-summary
)
"%PY%" "%HERE%analyze_gdr8050l_v109_readcap_route.py" "%HERE%gdr8050l_readcap_route_0729_*_v109_trace.csv" --out "%HERE%gdr8050l_readcap_0729_route_sweep_v109_summary.md"
echo [NEXT] Send gdr8050l_readcap_0729_route_sweep_v109_summary.md if you run the sweep.
endlocal
