Checksum Scripts
Lua scripts can serve as custom checksum calculators. Assigned via Settings > Checksum Settings — the dialog shows a single combo box with built-in algorithms and scripts.
The @checksum-script marker
Add -- @checksum-script in the first 512 bytes of the script.
Only scripts with this marker appear in the Checksum Settings dialog.
Behavior
- When a target with a script mapping is selected, the script runs automatically.
- The script calls
mp.ui.set_statusbar(label, value)— standard checksum widgets are hidden, the status bar shows a single"label: value"string. - When switching to a target without a script mapping,
mp.ui.reset_statusbar()restores standard widgets automatically.
Mappings
Stored in <config>/checksum_profiles.json:
[
{
"target_pattern": "K0R Auto Target",
"checksum_name": "",
"script_name": "renesas_nec_checksum.lua"
}
]
Example: renesas_nec_checksum.lua
-- renesas_nec_checksum.lua
-- @checksum-script
-- Calculates SUM-RL78 for Renesas RL78 (0x000-0x3FF)
-- and NEC 78K0R/78K0 (0x000-0x7FF)
local cfg = mp.config.get()
local target = cfg.target or ""
local family = cfg.family or ""
local RANGES = {
{ pattern = "RL78", start_addr = 0x0000, length = 0x400 }, -- 1 KB
{ pattern = "78K0R", start_addr = 0x0000, length = 0x800 }, -- 2 KB
{ pattern = "78K0", start_addr = 0x0000, length = 0x800 }, -- 2 KB
}
local range = nil
for _, r in ipairs(RANGES) do
if family:find(r.pattern) or target:find(r.pattern) then
range = r; break
end
end
if not range then
mp.log.warn("renesas_nec_checksum: unknown family, using default 0x400")
range = { start_addr = 0x0000, length = 0x400 }
end
local region = mp.memory.get_regions()[1]
local data = mp.memory.read_range(region, range.start_addr, range.length)
local sum = mp.checksum.sum_rl78(data)
mp.ui.set_statusbar(target .. " Block 0", string.format("0x%04X", sum))
This script ships in scripts/examples/renesas_nec_checksum.lua
and is wired in by default for RL78 / 78K0R / 78K0 targets.