Skip to content

Instantly share code, notes, and snippets.

@negative-seven
negative-seven / tetris_indirect_jump_times.lua
Last active January 21, 2024 00:20
NES Tetris cycle time calculator for reaching corruptable indirect jumps
--[[
script for the NES game Tetris with support for the NTSC, PAL, and three game cartridge versions, compatible with BizHawk 2.9.1, Mesen 0.9.9, and Mesen 2
on frames where the score addition routine gets run, calculates after how many cycles the "switch_s_plus_2a" subroutine is reached each time
intended to help analyze program counter corruption (game crash/ACE)
the script displays a table on screen showing the number of cycles between reaching the NMI handler and reaching "switch_s_plus_2a", on frames where score is calculated
columns "sw0" to "sw7" refer to the 8 times "switch_s_plus_2a" is reached
the "real" column shows the real cycle times, as measured with breakpoints
the "pred" column shows predicted cycle times, calculated at the start of the NMI based on the console state; the function calculating these contains comments detailing cycle times for particular parts of code
the "simp" column shows simplified cycle times, also calculated at the start of the NMI; the result should be the same as in t