Created
March 1, 2026 03:20
-
-
Save TakuikaNinja/1ad1c23ac4b344737b8c6284b14c3e6e to your computer and use it in GitHub Desktop.
Vs. System DIP Switch Setter for Mesen2
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: Vs. System DIP Switch Setter | |
| -- Author: TakuikaNinja | |
| ---------------------------------------------------------------------------------------------- | |
| -- Simulates the Vs. System's DIP switch settings, for games not tracked in Mesen2's database. | |
| ---------------------------------------------------------------------------------------------- | |
| -- DIP switch setting (8 bits) | |
| -- this is reversed from typical DIP switch ordering | |
| -- rightmost bit is switch 1, leftmost bit is switch 8 | |
| -- examples: 00000111 = free play in Vs. SMB | |
| dipSwitch = "00000000" | |
| -- Do not touch anything below this | |
| local consoleType = emu.getState()["consoleType"] | |
| if consoleType ~= "Nes" then | |
| emu.displayMessage("Script", "This script only works on the NES/FC.") | |
| return | |
| end | |
| P1_DATA = 0x18 -- %00011000 | |
| P2_DATA = 0xFC -- %11111100 | |
| function poll(address, value) | |
| local output = value | |
| local bits = 0 | |
| if address == 0x4016 then | |
| output = value & ~P1_DATA | |
| bits = (tonumber(dipSwitch,2) & 3) << 3 | |
| elseif address == 0x4017 then | |
| output = value & ~P2_DATA | |
| bits = tonumber(dipSwitch,2) & P2_DATA | |
| end | |
| -- compose & return final output | |
| output = (output | bits) & 0xff | |
| return output | |
| end | |
| emu.displayMessage("Script", "Vs. System DIP switch setter") | |
| emu.log(string.format("DIP switch = %#02x", tonumber(dipSwitch,2))) | |
| emu.addMemoryCallback(poll, emu.callbackType.read, 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