# The Legend of Heroes: Trails of Cold Steel IV 1.0.3
# BID: 59159483CF88330F
# Button polling is 2x more sensitive to holding any button

DECLARATIONS:
  -
    type: variable
    name: fps_lock
    value_type: uint32
    default_value: 33333333
    evaluate: "FRAMETIME_TARGET * 930000"
  -
    type: variable
    name: frame_time
    value_type: float
    default_value: 0.0333333333
  -
    type: code
    name: dynamicSpeed
    instructions: [
      [str, x0, [x19, 8]],
      [fcvt, s4, d0],
      [adrp, x8, $frame_time],
      [str, s4, [x8, $frame_time]],
      [ret]
    ]
MASTER_WRITE:
  # Move loading FPS lock time
  -
    type: asm_a64
    main_offset: 0x5F02F8
    instructions: [
      [adrp, x9, $fps_lock],
      [ldr, w9, [x9, $fps_lock]]
    ]
  # Write game's loop time as float
  -
    type: asm_a64
    main_offset: 0x5F0348
    instructions: [
      [bl, _dynamicSpeed()]
    ]
  - # Read lowest timing float factor
    type: asm_a64
    main_offset: 0x65548
    instructions: [
      [adrp, x8, $frame_time],
      [fminnm, s0, s0, s2],
      [ldr, s2, [x8, $frame_time]]
    ]


