Skip to content

Instantly share code, notes, and snippets.

@TakuikaNinja
Last active August 17, 2025 20:27
Show Gist options
  • Select an option

  • Save TakuikaNinja/cf2dab7ed4d5869c4be94a1753ffa76f to your computer and use it in GitHub Desktop.

Select an option

Save TakuikaNinja/cf2dab7ed4d5869c4be94a1753ffa76f to your computer and use it in GitHub Desktop.
Mesen2 Lua Script: Namco Serial Checker Interface
-----------------------
-- Name: Namco Serial Checker Interface
-- Author: TakuikaNinja
-----------------------
-- Simulates a serial interface used by some of Namco's FC/NES games.
-- Games attempt to receive/send data and verify it.
-- If successful, partial PRG/CHR checksums are calculated and verified.
-- The screen colour is set to magenta/green during this process.
-- This interface predates the IPL interface used by their FDS games. (1986~1987)
--
-- Successfully tested on games including:
-- "Babel no Tou (Japan).nes"
-- "Super Xevious: GAMP no Nazo (Japan).nes"
-- "Family Jockey (Japan).nes"
-----------------------
local consoleType = emu.getState()["consoleType"]
if consoleType ~= "Nes" then
emu.displayMessage("Script", "This script only works on the NES/FC.")
return
end
bits = {0,0,0,0} -- FIFO, start with 4 padding bits
SIZE = 4
writeIdx = 3
readIdx = 0
function strobe(address, value)
local currentBit = value & 1
bits[writeIdx+1] = currentBit
writeIdx = (writeIdx + 1) % SIZE
emu.log("$4016.d0 = " .. currentBit)
end
DATA = 0x08 -- %00001000, bit 3
count = 0
function poll(address, value)
local output = value & ~DATA -- preserve unused bits
local outBit = bits[readIdx+1] ~ 1 -- fetch bit and invert it
readIdx = (readIdx + 1) % SIZE
output = (output | (outBit * DATA)) & 0xff -- compose & return final output
emu.log("$4017.d3 = " .. outBit)
return output
end
script = "Namco Serial Checker"
emu.displayMessage("Script", script)
emu.addMemoryCallback(strobe, emu.callbackType.write, 0x4016)
emu.addMemoryCallback(poll, emu.callbackType.read, 0x4017)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment