# Code patch table for Astral Chain 1.0.1 (main build 4b159f0f7a360669738390ee8657b4f0).
# The spin waits below were found by tools/spin_waits.py on the update's ExeFS; recomp/gen.py checks every
# head and back-edge against the module before it emits anything.

# main: 32 spin waits
spin main 3e0724 3e0728   # 2 instructions; loads
spin main 3e39d8 3e39dc   # 2 instructions; loads
spin main 3e3e74 3e3e78   # 2 instructions; loads
spin main 3e415c 3e4160   # 2 instructions; loads
spin main 4be7fc 4be88c   # 6 instructions; loads
spin main 5009ac 5009c8   # 5 instructions; loads
spin main 500ac0 500adc   # 5 instructions; loads
spin main 5317d4 5317f0   # 5 instructions; loads
spin main 586314 586318   # 2 instructions; loads
spin main 73a40c 73a448   # 16 instructions; loads
spin main 7a7208 7a7210   # 3 instructions; loads
spin main 7a76c8 7a76d0   # 3 instructions; loads
spin main 7a7784 7a778c   # 3 instructions; loads
spin main 7afec8 7afed0   # 3 instructions; loads
spin main 7b0018 7b0020   # 3 instructions; loads
spin main 7b00e0 7b00e8   # 3 instructions; loads
spin main 7b0288 7b0290   # 3 instructions; loads
spin main 7b0320 7b0328   # 3 instructions; loads
spin main 7b04c0 7b04c8   # 3 instructions; loads
spin main 7b07e8 7b07f0   # 3 instructions; loads
spin main 7b0950 7b0958   # 3 instructions; loads
spin main 7cdacc 7cdb08   # 16 instructions; loads
spin main 7fa0e4 7fa0ec   # 3 instructions; loads
spin main 80a2d4 80a3f4   # 2 instructions; loads
spin main 80a4f0 80a610   # 2 instructions; loads
spin main 81b53c 81b544   # 3 instructions; loads
spin main 81b9e8 81b9f0   # 3 instructions; loads
spin main 81c71c 81c724   # 3 instructions; loads
spin main 8254d4 8254dc   # 3 instructions; loads
spin main 855894 855a50 855a64   # 36 instructions; loads
spin main 87adb0 87ade8   # 14 instructions; loads
spin main 9a8274 9a829c   # 5 instructions; loads

# Scene size for the upscaling modes (runtime/resolution.c scene_init: upscaling_quality quality, balanced, performance
# or ultra_performance with an upscaler able to run at start). The game keeps three dynamic-resolution levels, each with
# its own scene targets (light target, scene depth and the passes sized from them), made by the function at 40fb60
# (level, width, height); the per-frame selector at 4183a0 points the renderer at one level's targets, and the output
# and HUD stay at the render size (4328c0, which res / res1062 set). These six csel pick each level's width (w1) and
# height (w2) from the docked or handheld values; the helpers load the scene size from the patch page (+16, {w, h} as
# floats) instead, for both modes and every level, so the level the game picks no longer matters. The cmp before them
# stay res's / res1062's; at 40f1d8, which res and res1062 patch too, this set comes first in this file and so wins
# while it is on. Measured on the 1.0.1 frame (frame dumps at a 960x540 scene and a 1920x1080 output): the depth
# prepass, the light target, the bloom and the composite all follow, and the SMAA blending pass draws the composite into
# the output, the game's only scaling pass, where runtime/vk_dlaa.c runs the upscaler. Off unless the scene is smaller
# than the game resolution: without an upscaler the game's plain scaling would show it at 33..67 % of the output. Read
# at start; the game makes its scene targets once, so a change waits for a restart.
set  scene AC_PATCH_SCENE 0
site scene main 40f18c 1a930001 @fn:rt_res_scene_w1   # csel w1, w0, w19, eq (level 0 width)
site scene main 40f190 1a940102 @fn:rt_res_scene_h2   # csel w2, w8, w20, eq (level 0 height)
site scene main 40f1b8 1a880121 @fn:rt_res_scene_w1   # csel w1, w9, w8, eq (level 1 width)
site scene main 40f1bc 1a9402c2 @fn:rt_res_scene_h2   # csel w2, w22, w20, eq (level 1 height)
site scene main 40f1d8 1a880261 @fn:rt_res_scene_w1   # csel w1, w19, w8, eq (level 2 width)
site scene main 40f1dc 1a9402c2 @fn:rt_res_scene_h2   # csel w2, w22, w20, eq (level 2 height)

# 1062p (no dynamic resolution): KeatonTheBot's pchtxt for 1.0.1. The pchtxt's @flag offset_shift 0x100 names module
# offsets after the shift; these are those offsets. Width 0x760 = 1888, height 0x426 = 1062. Off by default: res
# below takes the same sites (runtime/resolution.c res_pick keeps one of the two on).
set  res1062 AC_RES1062 0
site res1062 main 4328c0 5280c808 5280ec08   # mov w8, #1600 -> #1888 (render width)
site res1062 main 4328c8 52807088 528084c8   # mov w8, #900 -> #1062 (render height)
site res1062 main 40d5e4 5280c809 5280ec09   # mov w9, #1600 -> #1888 (docked)
site res1062 main 40d5f0 52807089 528084c9   # mov w9, #900 -> #1062
site res1062 main 40fb04 5280c809 5280ec09   # mov w9, #1600 -> #1888 (handheld)
site res1062 main 40fb14 52807089 528084c9   # mov w9, #900 -> #1062
site res1062 main 40f184 7119001f 711d801f   # cmp w0, #1600 -> #1888 (ladder)
site res1062 main 40f188 52807088 528084c8   # mov w8, #900 -> #1062
site res1062 main 40f1a4 321603e8 5280a008   # mov w8, #1024 -> #1280
site res1062 main 40f1a8 5280b409 5280ec09   # mov w9, #1440 -> #1888
site res1062 main 40f1ac 7119001f 711d801f   # cmp w0, #1600 -> #1888
site res1062 main 40f1b0 52804ed4 52805a14   # mov w20, #630 -> #720
site res1062 main 40f1b4 52806556 528084d6   # mov w22, #810 -> #1062
site res1062 main 40f1d0 7119001f 711d801f   # cmp w0, #1600 -> #1888
site res1062 main 40f1d8 1a880261 1a880001   # csel w1, w19, w8, eq -> w0 (level 2 docked width, as res)
site res1062 main 9ed178 bc687920 1e2e1000   # ldr s0, [x9,x8,lsl #2] -> fmov s0, #1.0 (mipmap bias)

# The game resolution (runtime/resolution.c res_pick, AC_OUTPUT_RES): the res1062 sites, each taking the output size
# from the patch page (+32: width, +36: height, u32) instead of a constant, so any size runs without a set of its own,
# as the TotK Recomp's output set does. 1920x1080 by default, as 1.0.0's res1080 set, the ladder's docked entries
# included, so the scene stays at the output size whatever scale the dynamic-resolution logic picks. Only 16:9 sizes of
# 32n x 18n are taken (resolution.c res_size): 1280x800 lost the device, and in handheld took the docked entries below.
# Each ladder level picks one size when the scene target has the docked width and another when it has not; handheld
# (1280x720 targets, main+0x40d5a0) always takes the second. Those two handheld entries (40f1a4 and 40f1b0) get
# res1062's 1280x720, the handheld targets' own size: a larger size there is larger than the targets the game made for
# handheld, the level's target is never created, and loading a save in handheld read through its null texture in
# main+0x9d0df0 (issues #25 and #38). Level 2's docked width is w19, which the function sets to the handheld 1280 before
# the ladder (main+0x40f128, also the width of a 1280x720 target it makes there, so left alone): with the height raised
# to 1080 that level was 1280x1080, and the former AC_SSAA=1440p made it 1707x1440, which lost the device on an RTX 5070
# Ti (issue #51). 40f1d8 takes the scene target's width (w0) instead, as level 0 does, so the level has the output size
# docked and keeps 800x720 in handheld. res1062 gets the same site.
# Above 1080p the render size alone (0x4328c0) breaks start-up: the game's render targets and its three window textures
# (main+0x9e8620; general textures through main+0x9ead20) come out of one budget the graphics configuration sets at
# main+0x40e0b0 (+0x88: 0x13600000, 310 MiB), carved from the process heap. At 1080p its 81 allocations take 304 MiB;
# at 1440p one fails, the device setup gives up quietly, and start-up crashes reading a list it never filled
# (main+0x9c0cd0). So the budget follows the output's pixel count (rt_res_budget_w8; measured over 75 s into play:
# 1440p took 482 MiB, 2160p 955 MiB, the same 81 allocations), and the process heap grows by the same amount
# (resolution.c res_heap_extra_bytes; without it the game prints NN_MEMORY_INFO with the shortfall).
set  res AC_RES 1
site res main 4328c0 5280c808 @fn:rt_res_w8      # mov w8, #1600 -> output width (render width)
site res main 4328c8 52807088 @fn:rt_res_h8      # mov w8, #900 -> output height (render height)
site res main 40d5e4 5280c809 @fn:rt_res_w9      # mov w9, #1600 -> width (docked)
site res main 40d5f0 52807089 @fn:rt_res_h9      # mov w9, #900 -> height
site res main 40fb04 5280c809 @fn:rt_res_w9      # mov w9, #1600 -> width (handheld)
site res main 40fb14 52807089 @fn:rt_res_h9      # mov w9, #900 -> height
site res main 40f184 7119001f @fnz:rt_res_cmp_w0 # cmp w0, #1600 -> cmp w0, width (ladder)
site res main 40f188 52807088 @fn:rt_res_h8      # mov w8, #900 -> height
site res main 40f1a4 321603e8 5280a008           # mov w8, #1024 -> #1280 (handheld, as res1062)
site res main 40f1a8 5280b409 @fn:rt_res_w9      # mov w9, #1440 -> width
site res main 40f1ac 7119001f @fnz:rt_res_cmp_w0 # cmp w0, #1600 -> cmp w0, width
site res main 40f1b0 52804ed4 52805a14           # mov w20, #630 -> #720 (handheld, as res1062)
site res main 40f1b4 52806556 @fn:rt_res_h22     # mov w22, #810 -> height
site res main 40f1d0 7119001f @fnz:rt_res_cmp_w0 # cmp w0, #1600 -> cmp w0, width
site res main 40f1d8 1a880261 1a880001           # csel w1, w19, w8, eq -> w0 (level 2 docked width: the output's)
site res main 9ed178 bc687920 1e2e1000           # ldr s0, [x9,x8,lsl #2] -> fmov s0, #1.0 (mipmap bias, as res1062)
site res main 40e0b0 52a26c08 @fn:rt_res_budget_w8   # mov w8, #0x13600000 -> the budget for the output size
# The GRAPHIC BUFFER heap (143 MiB, made inside BUFFER ROOT by the heap setup at main+0x575a00) holds the constant
# buffers and one storage buffer of 6.97 bytes a pixel of the render size. At 3840x2160 that buffer takes 55 MiB, the
# heap ran full in File 02 and its block headers were overwritten, which crashed the allocator at the next free
# (runtime/resolution.c res_gbuf_extra has the measurements). Both sizes grow with the output's pixel count above 1080p.
site res main 575a30 52a15ac1 @fn:rt_res_bufroot_w1  # mov w1, #0xad60000 -> BUFFER ROOT's size for the output size
site res main 575c94 52a11e01 @fn:rt_res_gbuf_w1     # mov w1, #0x8f00000 -> the GRAPHIC BUFFER heap's size
# Field of view (AC_FOV, runtime/resolution.c res_fov_live). A camera's lens (*(camera+0x58)) keeps the vertical view
# angle at +0x27c (radians: 50 degrees in play, the shot's own in cutscenes), the aspect ratio at +0x278 and near / far
# at +0x270 / +0x274. While the lens is dirty (+0x28c), main+0x9a3010 loads those four and builds the projection
# matrix at lens+0x40 (bl main+0x9b28e0); main+0x9a3054 builds the same for a second target. The scene setup also
# copies the angle into the render scene at +0x140 for its screen-size work (two copies of that sequence). Each site
# multiplies the loaded or stored angle by the factor on page +60 (rt_fov_s0), so the projection, the culling built
# from it and the screen sizes stay in step; while the game's cutscene flag is set the angle passes unscaled, so
# cutscenes keep their framing. Off while AC_FOV is 100, so the camera code is the game's own.
# The two projection sites are the wide set's too (a taller frame's angle, below); this set comes first and wins there,
# so its helpers for them apply that angle as well (resolution.c rt_fov_lens24_s0).
set  fov AC_FOV_PATCH 0
site fov main 9a3010 bd427f00 bd427f00 @fn:rt_fov_lens24_s0   # ldr s0,[x24,#0x27c]; then s0 *= factor (projection)
site fov main 9a3054 bd427d00 bd427d00 @fn:rt_fov_lens8_s0    # ldr s0,[x8,#0x27c]; then s0 *= factor (second target)
site fov main 998b5c bd014260 @fn:rt_fov_s0 bd014260   # str s0,[x19,#0x140] -> s0 *= factor; the same store
site fov main 998f90 bd014260 @fn:rt_fov_s0 bd014260   # str s0,[x19,#0x140] -> s0 *= factor; the same store
# Draw distance (AC_DRAW_DISTANCE, runtime/resolution.c res_drawdist_live). A model holds up to four rates in 0..1 at
# *(model+0x390), their count at +0x398: DistRate0, DistRate1 and DistRate2, the thresholds between its levels of
# detail (LOD0 to LOD3), and LostDistRate, below which the model is not drawn while UseLostLOD (+0x3a0) is set. The
# model's set-up (main+0x551bc0) stores the defaults 0.7, 0.2, 0.1 and 0.0005; the reader of a model's named
# parameters (main+0x55eee0) stores the values the model names, clamped to 0..1. Each store gets the rate divided by
# the factor on page +80 (rt_drawdist_w9 for the defaults' bit patterns, rt_drawdist_s0 for the named values), so the
# finer level and the model itself last to a greater distance. Measured in Harmony Square: a scene load stores about
# 4100 default and 1800 named rates; with the rates times four the cars and passers-by of the street are gone, with a
# quarter of them the alley yard shows about 15 red shards where the game's own rates show 3. Off while
# AC_DRAW_DISTANCE is 100, so the rates are the game's own.
set  drawdist AC_DRAW_DISTANCE_PATCH 0
site drawdist main 551df0 b9000109 @fn:rt_drawdist_w9 b9000109   # str w9,[x8]: the default DistRate0 (0.7)
site drawdist main 551e0c b9000509 @fn:rt_drawdist_w9 b9000509   # str w9,[x8,#4]: the default DistRate1 (0.2)
site drawdist main 551e28 b9000909 @fn:rt_drawdist_w9 b9000909   # str w9,[x8,#8]: the default DistRate2 (0.1)
site drawdist main 551e44 b9000d09 @fn:rt_drawdist_w9 b9000d09   # str w9,[x8,#0xc]: the default LostDistRate (0.0005)
site drawdist main 55f0ec bd000100 @fn:rt_drawdist_s0 bd000100   # str s0,[x8]: a model's DistRate0
site drawdist main 55f134 bd000500 @fn:rt_drawdist_s0 bd000500   # str s0,[x8,#4]: a model's DistRate1
site drawdist main 55f17c bd000900 @fn:rt_drawdist_s0 bd000900   # str s0,[x8,#8]: a model's DistRate2
site drawdist main 55f1c4 bd000d00 @fn:rt_drawdist_s0 bd000d00   # str s0,[x8,#0xc]: a model's LostDistRate

# Dynamic frame rate for the 60 fps mode (the menu's AC_FPS: 30 = shipping 30 fps, 60 = 60 fps with the fix).
# The game's frame timer (main+0x91DBB0) clamps its step to [1, 2] frames of 1/30 s, so at 60 fps everything runs at
# twice its speed. The set replaces the timer's step with the frame's real time (runtime/frame_rate.c rt_fps_timer,
# which also keeps the whole 30 fps ticks the steps add up to), and fixes what counts frames instead of reading the
# step: every input/action/hitstop/rumble frame counter is scaled by the whole ticks so its window lasts wall-clock time
# instead of whole 60 fps frames; the camera's per-frame smoothing blend becomes 1 - powf(1 - a, clamp(step, 0, 4)); the
# dialogue text reveal, the time-scale channel test and the frame-counted cue scheduler follow the step. Cutscenes keep
# the game's fixed-step flag: in-engine ones step by the real time at 60 (frame_rate.c cutscene_step), and one with a
# full-screen movie is held to 30 presents per second (frame_rate.c cutscene_rate) and steps by the whole 30 fps
# frames of the real time (frame_rate.c held_step). Sites from the
# AstralChain-Dynamic-FPS mod v1.1.1 are marked so. AC_FPS=30 runs the original instructions (the shipping 30 fps).
set  fps60 FPS60 1
# frame call: request mode 0 (present interval 1) instead of mode 1 (interval 2, 30 fps); the present pacer
# (nvn_api_obj.c) holds 60 fps, and 30 in a cutscene with a full-screen movie
site fps60 main 3e39d0 320003e0 52800000   # orr w0, wzr, #1 -> mov w0, #0
# frame timer: the first call (no previous tick) publishes the game's step as the first ticks; every later call takes
# its step from rt_fps_timer and goes on at the tick store
site fps60 main 91dbdc b40006c8 @fn:rt_fps_timer_first b40006c8   # cbz x8,0x91dcb4; first: the same branch
site fps60 main 91dc10 340001d5 @fn:rt_fps_timer 14000029        # cbz w21,0x91dc48 -> step; b 0x91dcb4
# camera smoothing: the per-frame blend a becomes 1 - powf(1 - a, clamp(step, 0, 4))
site fps60 main 3a2d40 1e2a5808 @fn:rt_fps_cam_s0
site fps60 main 3a2d80 1e2a5828 @fn:rt_fps_cam_s1
site fps60 main 3a2dc0 1e29cd48 @fn:rt_fps_cam_fcsel
# dialogue text reveal: adds a fixed amount per frame; a talk line ends once its text and its voice are both done
site fps60 main 61600c bd40ae62 bd40ae62 @fn:rt_fps_text_rate_s2   # ldr s2,[x19,#0xac]; then s2 = that rate * step
# talk line state machine (main+0x6161D0): in a cutscene at 60 it runs only on frames with a whole 30 fps tick, so a
# line's state changes take a 30 fps frame each, as at 30
site fps60 main 6161e0 b940b268 @fn:rt_fps_talk_state_w8   # ldr w8,[x19,#0xb0] -> the state, or 4 (returns)
# event script, the talk command (main+0x443E50): in a cutscene at 60 it runs only on frames with a whole 30 fps tick
# and its countdowns take whole ticks, so its waits and reactions take the time they take at 30
site fps60 main 443e7c b909f11f @fn:rt_fps_talk_clear      # str wzr,[x8,#0x9f0] -> not on a skipped frame
site fps60 main 443e80 b9402b08 @fn:rt_fps_talk_busy_w8    # ldr w8,[x24,#0x28] -> 1 on a skipped frame
site fps60 main 443e88 320003f4 @fn:rt_fps_talk_ret_w8 2a0803f4   # mov w20,#1 -> w8 = 1, or 0 on a skipped frame; mov w20,w8
site fps60 main 443fa4 bd40d101 @fn:rt_fps_talk_wait_s1    # ldr s1,[x8,#0xd0] -> the step, or the whole ticks
site fps60 main 4453fc bd40d121 @fn:rt_fps_talk_wait_s1    # ldr s1,[x9,#0xd0] -> the step, or the whole ticks
# the voiced talk command (main+0x446C40, variant main+0x447600): the same; a state above 3 returns 0 at once
site fps60 main 446c5c b9404668 @fn:rt_fps_voiced_done_w8    # ldr w8,[x19,#0x44] -> 0 on a skipped frame
site fps60 main 446c80 b9404e68 @fn:rt_fps_voiced_alt_w8     # ldr w8,[x19,#0x4c] -> 0 on a skipped frame
site fps60 main 446ca4 b9402668 @fn:rt_fps_voiced_state_w8   # ldr w8,[x19,#0x24] -> the state, or 4 on a skipped frame
site fps60 main 4473dc bd40d101 @fn:rt_fps_talk_wait_s1      # ldr s1,[x8,#0xd0] -> the step, or the whole ticks
site fps60 main 447414 bd40d101 @fn:rt_fps_talk_wait_s1      # ldr s1,[x8,#0xd0] -> the step, or the whole ticks
site fps60 main 4477fc bd40d101 @fn:rt_fps_talk_wait_s1      # ldr s1,[x8,#0xd0] -> the step, or the whole ticks
# the other talk command (main+0x446300): the same, through its state (2 returns 0, still running, at once)
site fps60 main 44631c b9402668 @fn:rt_fps_msg_state_w8    # ldr w8,[x19,#0x24] -> the state, or 2 on a skipped frame
# time-scale getter (main+0x430DA0): with its flag set it returns channel 3 when that channel is below 1.0, meaning a
# slow-down scale is active. Channel 3 is the step times the channel scales, so at 60 fps (step 0.5) the test always
# held. It now compares against the step itself (x0 = the timer object after main+0x91D660), the same at 30 fps.
site fps60 main 430dd0 1e2e1001 bd40d001   # fmov s1,#1.0 -> ldr s1,[x0,#0xd0]
# frame-counted cue scheduler (main+0x6A3EC0): the counter adds the whole ticks and an entry fires when its frame is in
# (old counter, new counter] instead of equal to the counter
site fps60 main 6a3f28 11000508 @fn:rt_fps_cue_up_w8   # add w8,w8,#1 -> w8 += ticks
site fps60 main 6a3f38 6b08013f @fnz:rt_fps_cue_cmp    # cmp w9,w8 -> Z = entry due
site fps60 main 6a3f54 6b08013f @fnz:rt_fps_cue_cmp    # cmp w9,w8 -> Z = entry due (next entries)
# (the cut clock's end test, which a cutscene at 60 needs exact, is in the avsync set below)
# diagnostics (AC_TRACE=perf): the scene clock the event kept, after its update (main+0x8B7C60)
site fps60 main 8b7cb0 b9402a68 b9402a68 @fn:rt_cut_state   # ldr w8,[x19,#0x28]; then log cut changes and stops
# the game's audio sync of an event with a voice track (main+0x8B9DC0, twin main+0x8C2E10): s0 = the track's position
# minus the picture's, in seconds, recorded for the log (frame_rate.c rt_cut_drift_s0); no change to what it does
site fps60 main 8b9eac 1e202820 1e202820 @fn:rt_cut_drift_s0   # fadd s0,s1,s0; then record s0
site fps60 main 8c2efc 1e202820 1e202820 @fn:rt_cut_drift_s0   # fadd s0,s1,s0; then record s0
# step -> integer frame-count readers (fcvtzs/fcvtzu): read the whole-tick count instead of floor(step)
site fps60 main 48be14 1e380008 @fn:rt_fps_ticks_w8   # fcvtzs w8,s0 -> w8 = whole ticks
site fps60 main 57e7dc bd40d300 @fn:rt_fps_ticks_w8   # ldr s0,[x24,#0xd0] -> w8 = whole ticks
site fps60 main 57e7e0 1e390008 34000188              # fcvtzu w8,s0 -> cbz w8, 0x57e810
# input/action frame counters, scaled by the whole-tick count (subs wN,wN,#1 -> the hs helpers)
site fps60 main 308a9c 71000508 @fnz:rt_fps_hs_w8   # combo cue
site fps60 main 0e7f64 71000508 @fnz:rt_fps_hs_w8   # 15-count
site fps60 main 0f7ce8 71000508 @fnz:rt_fps_hs_w8   # chain bind
site fps60 main 0f8720 71000508 @fnz:rt_fps_hs_w8   # S3 15-count
site fps60 main 0d5e28 71000508 @fnz:rt_fps_hs_w8   # S3 exact-zero
site fps60 main 2828ac 71000508 @fnz:rt_fps_hs_w8   # short latch
site fps60 main 283100 71000508 @fnz:rt_fps_hs_w8   # buffer
site fps60 main 28311c 71000508 @fnz:rt_fps_hs_w8   # tap buffer (double-tap)
site fps60 main 28759c 71000508 @fnz:rt_fps_hs_w8   # buffer
site fps60 main 2875ac 71000508 @fnz:rt_fps_hs_w8   # buffer
site fps60 main 2875bc 71000508 @fnz:rt_fps_hs_w8   # buffer
site fps60 main 2875cc 71000508 @fnz:rt_fps_hs_w8   # buffer
site fps60 main 2875dc 71000508 @fnz:rt_fps_hs_w8   # buffer
site fps60 main 285464 71000508 @fnz:rt_fps_hs_w8   # queue window
site fps60 main 283360 71000508 @fnz:rt_fps_hs_w8   # exact-zero
site fps60 main 284ad4 71000508 @fnz:rt_fps_hs_w8   # window
site fps60 main 286e38 71000508 @fnz:rt_fps_hs_w8   # window
site fps60 main 286f98 71000508 @fnz:rt_fps_hs_w8   # window
site fps60 main 287044 71000508 @fnz:rt_fps_hs_w8   # window
site fps60 main 284af0 71000508 @fnz:rt_fps_hs_w8   # window
site fps60 main 284bb8 71000508 @fnz:rt_fps_hs_w8   # window
site fps60 main 284bf4 71000508 @fnz:rt_fps_hs_w8   # window
site fps60 main 284b00 71000508 @fnz:rt_fps_hs_w8   # r5 window
site fps60 main 288f40 71000529 @fnz:rt_fps_hs_w9   # lockout bank
site fps60 main 288f5c 71000529 @fnz:rt_fps_hs_w9
site fps60 main 288f78 71000529 @fnz:rt_fps_hs_w9
site fps60 main 288f94 71000529 @fnz:rt_fps_hs_w9
site fps60 main 288fb0 71000529 @fnz:rt_fps_hs_w9
site fps60 main 288fcc 71000529 @fnz:rt_fps_hs_w9
site fps60 main 288fe8 71000529 @fnz:rt_fps_hs_w9
site fps60 main 289004 71000529 @fnz:rt_fps_hs_w9
site fps60 main 289020 71000529 @fnz:rt_fps_hs_w9
site fps60 main 28903c 71000529 @fnz:rt_fps_hs_w9
site fps60 main 289244 71000529 @fnz:rt_fps_hs_w9
site fps60 main 289260 71000529 @fnz:rt_fps_hs_w9
site fps60 main 28927c 71000529 @fnz:rt_fps_hs_w9
site fps60 main 289298 71000529 @fnz:rt_fps_hs_w9
site fps60 main 2856f8 71000529 @fnz:rt_fps_hs_w9   # press window
site fps60 main 283294 71000529 @fnz:rt_fps_hs_w9   # window
site fps60 main 287738 71000529 @fnz:rt_fps_hs_w9   # r5 window
site fps60 main 28783c 71000529 @fnz:rt_fps_hs_w9   # r5 window
site fps60 main 283a94 7100054a @fnz:rt_fps_hs_w10  # lockout (subs w10,w10,#1)
site fps60 main 287694 71000549 @fnz:rt_fps_hs_w10w9  # second-tap window, path A
site fps60 main 287724 71000549 @fnz:rt_fps_hs_w10w9  # second-tap window, path B
# stick gesture parser (main+0x322BE0, once a frame from the player input update): eight direction-sector timers
# (12 frames, a 360 motion needs 6 of them live), the rotation window, and the press windows a stick reversal is read
# from. A push opens a 5-frame window and stores its angle; a second push inside the window whose angle differs enough
# arms the reversal (+0x153C), the back-to-forward input. At 60 fps the window lasted 83 ms, shorter than a stick takes
# through neutral, so back-to-forward could not be done on a gamepad (issue #40).
site fps60 main 322bf8 71000508 @fnz:rt_fps_hs_w8   # +0x1508 sector timer
site fps60 main 322c10 51000508 @fn:rt_fps_sub_w8   # +0x150C sector timer (sub, after a > 0 test)
site fps60 main 322c1c 71000508 @fnz:rt_fps_hs_w8   # +0x1510 sector timer
site fps60 main 322c2c 71000508 @fnz:rt_fps_hs_w8   # +0x1514 sector timer
site fps60 main 322c3c 71000508 @fnz:rt_fps_hs_w8   # +0x1518 sector timer
site fps60 main 322c4c 71000508 @fnz:rt_fps_hs_w8   # +0x151C sector timer
site fps60 main 322c5c 71000508 @fnz:rt_fps_hs_w8   # +0x1520 sector timer
site fps60 main 322c6c 71000508 @fnz:rt_fps_hs_w8   # +0x1524 sector timer
# sector stamp: at 60 fps the denser sampling of a back-to-forward sweep stamped more sectors, and the rotation it then
# read cleared the reversal; stamped on whole-tick frames only, 30 samples a second as at 30 fps
site fps60 main 322d6c b9150909 @fn:rt_fps_sector_str   # str w9,[x8,#0x1508] -> only with a whole tick
site fps60 main 322d74 71000508 @fnz:rt_fps_hs_w8   # +0x1528 rotation window
site fps60 main 322e04 71000508 @fnz:rt_fps_hs_w8   # +0x153C reversal window, after a rotation
site fps60 main 322e3c 71000508 @fnz:rt_fps_hs_w8   # +0x153C reversal window
site fps60 main 322e4c 71000508 @fnz:rt_fps_hs_w8   # +0x1538 turn window
site fps60 main 322e5c 71000508 @fnz:rt_fps_hs_w8   # +0x1544 push window
site fps60 main 322e6c 71000508 @fnz:rt_fps_hs_w8   # +0x1548
site fps60 main 322e7c 71000508 @fnz:rt_fps_hs_w8   # +0x156C right-stick window
site fps60 main 322e8c 71000508 @fnz:rt_fps_hs_w8   # +0x155C push window
site fps60 main 322f0c 71000509 @fnz:rt_fps_hs_w8w9  # +0x1568 right-stick push window
site fps60 main 322f24 71000509 @fnz:rt_fps_hs_w8w9  # +0x1568, other path
site fps60 main 322fb0 71000508 @fnz:rt_fps_hs_w8   # +0x46B438
site fps60 main 322fc8 51000508 @fn:rt_fps_sub_w8   # +0x1530 press window (sub, after a > 0 test)
# player input update (main+0x282870): stick push windows, press-repeat window and a float frame countdown
site fps60 main 282a48 71000508 @fnz:rt_fps_hs_w8   # +0x46AE80 left-stick push window (3 frames)
site fps60 main 282a64 71000508 @fnz:rt_fps_hs_w8   # +0x46AE84 right-stick push window (3 frames)
site fps60 main 282fd0 71000529 @fnz:rt_fps_hs_w9   # +0x46B570
site fps60 main 282fec 71000529 @fnz:rt_fps_hs_w9   # +0x46B590
site fps60 main 2832e4 71000529 @fnz:rt_fps_hs_w9   # +0x46AE5C press-repeat window (5 frames)
site fps60 main 2833a0 1e3e1001 @fn:rt_fps_neg_step_s1   # +0x46ADB4 countdown: fmov s1,#-1.0 -> s1 = -step
# r2 bank of buffer counters (sub w8,w8,#1, no flags)
site fps60 main 283044 51000508 @fn:rt_fps_sub_w8
site fps60 main 283054 51000508 @fn:rt_fps_sub_w8
site fps60 main 283064 51000508 @fn:rt_fps_sub_w8
site fps60 main 283074 51000508 @fn:rt_fps_sub_w8
site fps60 main 283084 51000508 @fn:rt_fps_sub_w8
site fps60 main 283094 51000508 @fn:rt_fps_sub_w8
site fps60 main 2830a4 51000508 @fn:rt_fps_sub_w8
site fps60 main 2830b4 51000508 @fn:rt_fps_sub_w8
site fps60 main 2830c4 51000508 @fn:rt_fps_sub_w8
site fps60 main 2830d4 51000508 @fn:rt_fps_sub_w8
site fps60 main 2830e4 51000508 @fn:rt_fps_sub_w8
site fps60 main 2830f4 51000508 @fn:rt_fps_sub_w8
site fps60 main 283138 51000508 @fn:rt_fps_sub_w8
site fps60 main 283148 51000508 @fn:rt_fps_sub_w8
site fps60 main 283158 51000508 @fn:rt_fps_sub_w8
site fps60 main 283168 51000508 @fn:rt_fps_sub_w8
site fps60 main 283178 51000508 @fn:rt_fps_sub_w8
site fps60 main 283188 51000508 @fn:rt_fps_sub_w8
site fps60 main 283198 51000508 @fn:rt_fps_sub_w8
site fps60 main 2831a8 51000508 @fn:rt_fps_sub_w8
site fps60 main 2831b8 51000508 @fn:rt_fps_sub_w8
site fps60 main 2831c8 51000508 @fn:rt_fps_sub_w8
site fps60 main 2831dc 51000508 @fn:rt_fps_sub_w8
# pad auto-repeat count, from AstralChain-Dynamic-FPS v1.1.1 (add w9,w9,#1, no flags)
site fps60 main 9abf40 11000529 @fn:rt_fps_up_w9
# hitstop manager's frame counters, from AstralChain-Dynamic-FPS v1.1.1
site fps60 main 4f3d30 71000508 @fnz:rt_fps_hs_w8   # +0x38 delay
site fps60 main 4f3d5c 71000508 @fnz:rt_fps_hs_w8   # +0x34 scale duration
site fps60 main 4f3d98 71000508 @fnz:rt_fps_hs_w8   # +0x48 scale duration
site fps60 main 4f3e64 71000508 @fnz:rt_fps_hs_w8   # +0x48, after +0x34 expires
site fps60 main 4f3db0 71000508 @fnz:rt_fps_hs_w8   # +0x74 scale duration
site fps60 main 4f3e78 71000508 @fnz:rt_fps_hs_w8   # +0x74, after +0x48 expires
site fps60 main 4f3e4c 71000508 @fnz:rt_fps_hs_w8   # +0xa8 request suppression
site fps60 main 4f3f04 71000508 @fnz:rt_fps_hs_w8   # +0xa8, other path
site fps60 main 4f3f14 71000508 @fnz:rt_fps_hs_w8   # +0xa4 scale duration
site fps60 main 4f3f3c 71000508 @fnz:rt_fps_hs_w8   # +0x54 scale duration
site fps60 main 4f3f88 71000508 @fnz:rt_fps_hs_w8   # +0x54, after +0xa4 expires
site fps60 main 4f3f54 71000508 @fnz:rt_fps_hs_w8   # +0x80 hold request delay
site fps60 main 4f3fb0 71000508 @fnz:rt_fps_hs_w8   # +0x8c cue delay
site fps60 main 4f41b0 71000508 @fnz:rt_fps_hs_w8   # +0xb4 window
site fps60 main 4f4010 51000529 @fn:rt_fps_floor1_w9   # +0x8c, stays at 1 or above
site fps60 main 4f4018 11000508 @fn:rt_fps_up_w8       # +0x84 freeze phase count
site fps60 main 4f4070 bd4e1d01 bd4e1d01 @fn:rt_fps_ramp_s1   # +0x7c ramp: 1/60 a frame, times the ticks
# player's deferred hitstop, from AstralChain-Dynamic-FPS v1.1.1
site fps60 main 32cac8 71000529 @fnz:rt_fps_hs_w9   # +0x7e88
site fps60 main 32cdc0 71000529 @fnz:rt_fps_hs_w9   # +0x7e94
site fps60 main 32d0b8 71000529 @fnz:rt_fps_hs_w9   # +0x7e80
# tap/hold and lockout counts, from AstralChain-Dynamic-FPS v1.1.1
site fps60 main 286c2c 11000529 @fn:rt_fps_up_min1_w9  # +0xc50 tap/hold count: on release 1..9 is a tap, 10 or more a hold
site fps60 main 2846f0 1100052a @fn:rt_fps_up_w9w10    # +0x46b62c lockout count: ends at 15
# rumble channel counts, from AstralChain-Dynamic-FPS v1.1.1
site fps60 main 9abc68 71000509 @fnz:rt_fps_rumble_w8w9
site fps60 main 9abc7c 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abcc0 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abd34 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abcdc 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abd50 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abdd0 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abd6c 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abdec 7100052a @fnz:rt_fps_rumble_w9w10
site fps60 main 9abe8c 7100052a @fnz:rt_fps_rumble_w9w10
# per-object clock scale's delay and duration (armed at 91d6a0), from AstralChain-Dynamic-FPS v1.1.1
site fps60 main 91de50 71000610 @fnz:rt_fps_hs_w16        # +0x34 delay
site fps60 main 91dee8 71000610 @fnz:rt_fps_duration_w16  # +0x30 duration
# sibling paths of two input counters above, from AstralChain-Dynamic-FPS v1.1.1
site fps60 main 0d5dd4 71000508 @fnz:rt_fps_hs_w8   # +0x2024, sibling of 0d5e28
site fps60 main 2876d4 71000508 @fnz:rt_fps_hs_w8   # +0x14d4, sibling of 28759c

# Full-screen movies (runtime/frame_rate.c rt_movie_*): the game's Bink player (open main+0x9BEFD0) tells the runtime
# which open handles are full-screen movies (1280x720 or more) and when one last waited for its next frame, so a
# cutscene with a movie keeps the 30 fps hold. Its own set, on at 30 fps too, so a movie opened before a switch to 60
# is known.
set  movies AC_MOVIE_TRACK 1
site movies main 9bf058 f9000680 @fn:rt_movie_opened f9000680   # str x0,[x20,#8] after BinkOpen; the handle first
site movies main 9bf26c 97f502cd @fn:rt_movie_close 97f502cd    # bl BinkClose; the handle first
site movies main 9bf430 97f503ec @fn:rt_movie_wait 97f503ec     # bl BinkWait
site movies main 9bf514 97f503b3 @fn:rt_movie_wait 97f503b3     # bl BinkWait
site movies main 9bf6a8 97f5034e @fn:rt_movie_wait 97f5034e     # bl BinkWait

# The picture kept with the sound (runtime/frame_rate.c). The game's sound plays on the audio device's
# clock whatever the picture does, so a cutscene whose frames come late has to make up for them. On at 30 fps and at
# 60; the helpers change nothing while the frames come on time.
set  avsync AC_AVSYNC_PATCH 1
# A movie ("Keeping a movie with its sound" in frame_rate.c; its helpers go by the movies set's tracking). The event
# movies have no sound track, so Bink never skips a frame of one, and a cutscene with a movie presents 30 times a
# second at most: a frame shown late stayed late. BinkWait's subtraction (main+0x7003E0: the timer since the sync
# point minus the next frame's due time) hands the runtime how late the movie is and no longer takes a new sync point
# for a delay the skipped frames can make up; the player's read of BinkShouldSkip's answer (in its decode,
# main+0x9BF6F0) then skips a frame of a movie that is a frame and a half late, by the game's own code for it.
site avsync main 7004d4 6b090149 @fnz:rt_movie_late_w9          # subs w9,w10,w9 -> the same, recorded; w9 capped
site avsync main 9bf760 340003e0 @fn:rt_movie_skip_w0 340003e0  # cbz w0,0x9bf7dc; before it w0 = 1 for a late movie
# At 30 fps the game's own timer runs (the fps60 set's site at main+0x91DC10 branches past this one): its fixed step,
# 1.0 while the cutscene flag is set, becomes the whole 30 fps frames of the real time (frame_rate.c rt_fixed_step).
site avsync main 91dc48 bd00d268 @fn:rt_fixed_step              # str s8,[x19,#0xd0] -> the step stored by the helper
site avsync main 91dc14 bd40da61 @fn:rt_free_step bd40da61      # ldr s1,[x19,#0xd8], the free step: a cutscene run ended
# cut clock (main+0x8C2410), the end of a cut: the game's own test, unless the frame steps a cutscene by other than
# 1.0 (a cutscene at 60, or a held one making up for late frames), where a cut goes on while its time is below its
# length and the next cut starts at what the step went past it
site avsync main 8c2550 1e283821 @fn:rt_cut_hold_s1   # fsub s1,s1,s8 -> len - rate, or just below len
site avsync main 8c255c bd400680 @fn:rt_cut_prev_s0   # ldr s0,[x20,#4] -> the old time, or s1 (no hold)
site avsync main 8c2568 1e2703e1 @fn:rt_cut_next_s1   # fmov s1,wzr -> 0, or the overshoot

# Wide pictures (the aspect setting's wide, AC_ASPECT=wide; runtime/resolution.c res_wide_tick). The game renders 16:9
# whatever the window's shape (off the 32n x 18n grid it loses the device, resolution.c res_output_grid), so a wider
# window gets the same 16:9 targets drawn with a wider camera, and the present stretches that picture back to the
# camera's shape (gfx_present.c gfx_fit_rect). A taller window (16:10, down to 4:3) gets them drawn with a taller one
# that keeps the 16:9 view's width: more of the world above and below instead of black bars. A camera's lens (*(handle), handle = camera+0x58 for the game's cameras)
# keeps its viewport {x, y, width, height} at +0x260 and the aspect ratio at +0x278; main+0x9a30a0 fills both from a
# width and a height and has three callers: the game camera (main+0x3a2398, 1280x720), the interface camera
# (main+0x9045d4, 1280x720, a 20 degree lens 2040 units in front of the 1280x720 plane, made by the message system) and
# a 256x256 one (main+0x3c0ccc). main+0x9a2fa0 builds a lens's view matrix, and its projection while the lens is dirty
# (+0x28c); the game camera goes through it each frame (main+0x88f730). The site there hands a 16:9 lens the frame's
# ratio and marks it dirty when its ratio differs, so the ratio follows the window, and goes back to 16:9 while a
# full-screen movie plays (frame_rate.c rt_movie_showing): the movie is a 16:9 picture, shown between black bars.
# The interface camera's matrices are built once, when the message system starts (main+0x9045f4); the interface drawn
# through it keeps its proportions when its lens has the frame's ratio too, in the middle 16:9 of the picture, so the
# site's helper builds them again, with the game's own call, whenever the frame's ratio changed (resolution.c
# rt_wide_dirty_w8).
# The idea and the lens function are from TLin-Y's aspect-ratio pchtxt for 1.0.1 (Fl4sh9174/Switch-Emulator-Ultrawide-
# FPS-Mods, pull request 286), which writes one constant ratio into every lens and leaves the interface camera's
# matrices unbuilt, the interface stretched with the picture; no code copied.
# The game's visibility cone (main+0x991240: an object outside it and beyond its own distance is not shown) is the
# lens's vertical half angle plus 20 degrees around the camera's axis, 45 degrees in play, which holds a 16:9 picture's
# corners (43.4 degrees) and no more; a 21:9 picture's are at 50.4. Its site widens the half angle by the ratio's
# share over 16:9, or a taller picture's by 16:9's share over its ratio (rt_wide_cone_s0).
# A lens's projection takes its vertical angle (+0x27c) and its ratio; a taller ratio at the same angle would only cut
# the sides off, so where the projection is built from the angle (the fov set's two sites, which win while a field of
# view is set and do the same) a lens made 16:9 that holds a taller ratio gets the angle whose picture is as wide as
# the 16:9 one (rt_wide_angle24_s0). The lens keeps the game's angle, which the game may read back.
set  wide AC_WIDE_PATCH 0
site wide main 9a3004 b9428f08 @fn:rt_wide_dirty_w8   # ldr w8,[x24,#0x28c] -> the lens's ratio brought up to date; w8 = dirty
site wide main 99132c 1e2c1001 @fn:rt_wide_cone_s0 1e2c1001   # fmov s1,#0.5; before it s0 = the angle for the frame's ratio
site wide main 9a3010 bd427f00 bd427f00 @fn:rt_wide_angle24_s0   # ldr s0,[x24,#0x27c]; then the angle for a taller ratio
site wide main 9a3054 bd427d00 bd427d00 @fn:rt_wide_angle8_s0    # ldr s0,[x8,#0x27c]; the same (second target)
# World to screen and back (main+0x9a31f0, main+0x9a3270; the game cameras' main+0x88f760 and main+0x88f770) map a
# lens's picture onto its viewport, 1280x720 for the game camera, and what they return is used as a place on the
# interface's 1280x720 plane. With the interface camera at the frame's ratio that plane shows 720 x ratio units across
# (1280 / ratio down, in a taller frame), so the picture's edges are no longer at 0 and 1280 (0 and 720): both sites
# hand over a viewport of that width (height), centred.
site wide main 9a320c 91098088 @fn:rt_wide_view_x8    # add x8,x4,#0x260 -> the viewport for the frame's ratio
site wide main 9a327c 91098088 @fn:rt_wide_view_x8    # add x8,x4,#0x260 -> the same
# What is not drawn through the interface camera (the mission banner, the dialogue's lines, the civilians' markers)
# goes through a flat camera. The game makes three (main+0x9e4030; the array's address at *(main+0xdc2d50), 0x40 bytes
# each: bounds {left, right, bottom, top, near, far} at +0x18, a dirty word at +0x30) and uses the first only, which
# main+0x3bb7f4 gives the 1280x720 plane; main+0x9e3f70, called for each every frame (main+0x9e4420), writes a dirty
# one's matrices into its uniform block, and main+0x9e2080 binds camera w2's block for the draws that follow. That
# camera serves the screen and the interface's 1280x720 layers alike (the minimap's picture is drawn into one), so it
# keeps its plane; the site in main+0x9e3f70 keeps the second camera as the same plane at the width (or height) the
# frame's ratio shows (resolution.c rt_wide_flat_w8), and the interface layers drawn onto the screen bind that one where they begin
# (the layers and their begin functions are registered from main+0x409a08 to main+0x409fec, main+0x9e1f00). Layer
# 0x5d (main+0x3ffa90) and the flat pieces that bind the camera themselves (main+0x3defd0) keep the first one: they
# are effects that cover the picture, such as the IRIS mode's veil over the scene, and must reach its edges.
site wide main 9e3f84 b9403268 @fn:rt_wide_flat_w8    # ldr w8,[x19,#0x30] -> camera 1 brought up to date; w8 = dirty
site wide main 403670 2a1f03e2 52800022               # mov w2,wzr -> mov w2,#1: layer 0x63's camera (main+0x403660)
site wide main 403424 2a1f03e2 52800022               # the same, layer 0x66's (main+0x403420)
site wide main 403644 2a1f03e2 52800022               # layer 0x69's (main+0x403640)
site wide main 403704 2a1f03e2 52800022               # layer 0x6e's (main+0x403700)
# The HUD's blocks at the picture's edges. A block is an instance of a layout (a .uid file of an interface archive),
# a tree of parts; main+0x910f60 makes each part's world matrix every frame from its own and its parent's. The site,
# after a part's matrix is made, moves the top parts of the gameplay HUD's layouts whose content sits in the left or
# the right third of the 1280x720 plane to that side's edge of the wider plane, or in a taller frame those in the top
# or bottom third to the top or bottom edge (resolution.c rt_wide_anchor); what
# hangs on a moved part follows it, and the layouts of the menus, the centre of the screen and the markers placed on
# the world stay where they are.
site wide main 9111d8 9105c260 @fn:rt_wide_anchor 9105c260    # add x0,x19,#0x170; before it the world matrix moved

# The gameplay HUD switched off (the hud setting, F12; runtime/resolution.c res_hud_tick). An interface layout is drawn
# as an instance (its archive's number at +0xb4, its parts' array at +0x150 and their count at +0x160), and two
# functions send an instance's parts to the renderer, both through main+0x9126c0, which draws a part, its children and
# the parts after it: main+0x9177d0, the draw of an instance that has a layer of its own (the instance at +0x30 of
# x0, drawn while its byte at +0xd1 is set), and main+0x915e50, which takes the instances queued for a draw off their
# list one by one and draws those that have parts. Each site, after the load its function tests, clears x8 for an
# instance of the gameplay HUD's archive (hud2: the gauges, the map, the prompts and the markers over the world), so
# the function leaves it out as it does an instance without parts. The layouts keep being updated and nothing in the
# game's state changes: the HUD is back in the frame after the set goes off. The menus, the title screen, the dialogue
# and the loading screens are layouts of other archives and stay.
set  nohud AC_NOHUD_PATCH 0
site nohud main 9177ec 394346e8 394346e8 @fn:rt_hud_off23_x8   # ldrb w8,[x23,#0xd1]; then x8 = 0 for a HUD instance (x23)
site nohud main 915ea0 f940b2c8 f940b2c8 @fn:rt_hud_off22_x8   # ldr x8,[x22,#0x160]; the same (x22)
