Created
November 1, 2025 08:08
-
-
Save TakuikaNinja/f4c3310e0000e29291aa59cf9f246dda to your computer and use it in GitHub Desktop.
Mesen2 Lua Script: Namco Serial Checker Interface (SRAM)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ----------------------- | |
| -- Name: Namco Serial Checker Interface (SRAM) | |
| -- Author: TakuikaNinja | |
| ----------------------- | |
| -- Simulates a serial interface used by a few of Namco's FC/NES games which use battery-backed SRAM. | |
| -- It attempts to receive/send data and verify it. | |
| -- If successful, SRAM contents are then verified. | |
| -- The screen colour is set to blue if successful, otherwise it attempts to reinitialise SRAM. | |
| -- The screen colour is set to yellow if the reinitialisation succeeds, otherwise it is set to red. | |
| -- | |
| -- Successfully tested on games including: | |
| -- "Family Circuit '91 (Japan) (En).nes" | |
| -- "Splatterworld_ROM.nes" (Unreleased) | |
| ----------------------- | |
| local consoleType = emu.getState()["consoleType"] | |
| if consoleType ~= "Nes" then | |
| emu.displayMessage("Script", "This script only works on the NES/FC.") | |
| return | |
| end | |
| bit = 0 | |
| function strobe(address, value) | |
| local currentBit = value & 1 | |
| bit = currentBit | |
| emu.log("$4016.d0 = " .. currentBit) | |
| end | |
| DATA = 0x02 -- %00000010, bit 1 | |
| function poll(address, value) | |
| local output = value & ~DATA -- preserve unused bits | |
| local outBit = bit ~ 1 -- fetch bit and invert it | |
| output = (output | (outBit * DATA)) & 0xff -- compose & return final output | |
| emu.log("$4017.d1 = " .. outBit) | |
| return output | |
| end | |
| script = "Namco Serial Checker (SRAM)" | |
| 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