Created
May 15, 2026 11:45
-
-
Save TakuikaNinja/6fbee0263fde10d2e42b10b8e53db92f to your computer and use it in GitHub Desktop.
Mesen2/MesenCE Lua Script: FDS Wavetable Snooper
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: FDS Wavetable Snooper | |
| -- Author: TakuikaNinja | |
| ----------------------- | |
| -- Snoops FDS wavetable RAM writes for ripping purposes. | |
| -- Right mouse click toggles linear interpolation between points. | |
| -- Log format is compatible with FamiTracker (0-63, space separator). | |
| ----------------------- | |
| local consoleType = emu.getState()["consoleType"] | |
| if consoleType ~= "Nes" then | |
| emu.displayMessage("Script", "This script only works on the NES/FC.") | |
| return | |
| end | |
| hold_button = false | |
| line_mode = true | |
| write_enable = false | |
| wave_ram = {} | |
| -- sensible programs should be writing to all entries... | |
| for i = 1, 64 do | |
| wave_ram[i] = 0 | |
| end | |
| function checkWriteEnable(address, value) | |
| if (value & 0x80) > 0 then | |
| write_enable = true | |
| elseif write_enable then | |
| -- newly disabled writes likely means the program finished writing | |
| -- output the current wave RAM state | |
| write_enable = false | |
| emu.log(table.concat(wave_ram, " ") .. " ") -- extra space just to make copying easier | |
| end | |
| end | |
| function waveWrite(address, value) | |
| if write_enable then | |
| wave_ram[address - 0x403F] = value & 63 | |
| end | |
| end | |
| function displayWave() | |
| local BOX_X = 128 - 33 | |
| local BOX_Y = 4 | |
| local SIZE = 64 + 2 | |
| local BOX_COLOUR = 0x00FF00 | |
| local WAVE_COLOUR = 0xFF0000 | |
| if emu.getMouseState().right then | |
| if not hold_button then | |
| line_mode = not line_mode | |
| hold_button = true | |
| end | |
| else | |
| hold_button = false | |
| end | |
| emu.drawRectangle(BOX_X, BOX_Y, SIZE, SIZE, 0x80808080, true) | |
| emu.drawRectangle(BOX_X, BOX_Y, SIZE, SIZE, BOX_COLOUR, false) | |
| for i = 1, #wave_ram do | |
| local y = 64 - wave_ram[i] | |
| -- linear interpolation | |
| if line_mode and i > 1 then | |
| local prev_y = 64 - wave_ram[i-1] | |
| emu.drawLine(BOX_X + i - 1, BOX_Y + prev_y, BOX_X + i, BOX_Y + y, WAVE_COLOUR | 0xC0000000) | |
| end | |
| emu.drawPixel(BOX_X + i, BOX_Y + y, WAVE_COLOUR) | |
| end | |
| end | |
| script = "FDS Wavetable Snooper" | |
| emu.displayMessage("Script", script) | |
| emu.addMemoryCallback(checkWriteEnable, emu.callbackType.write, 0x4089) | |
| emu.addMemoryCallback(waveWrite, emu.callbackType.write, 0x4040, 0x407F) | |
| emu.addEventCallback(displayWave, emu.eventType.startFrame) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment