Skip to content

Logging with Mesen2 emulator

alekmaul edited this page Jun 5, 2026 · 3 revisions

Mesen2, named now MesenCE is the best emulator and debugger for Windows, Linux and MacOS.

If you want more information on it, you can consult the Github repository

Logging messages

It is very useful to add logs in your game to help debugging.
PVSneslib is shipped with a function to allow logs with no$sns emulator named consoleNocashMessage but it does not work with Mesen2.

For example, this prints System initialized successfully!"* in No$sns TTY Debug window a message.

// Sending a basic string literal
consoleNocashMessage("System initialized successfully!\n");

Mesen2 has the capabilities to run Lua script in parallel of the game.

We will create a new Lua script to Mesen2 to capture log as we do with no$sns.

Step-by-Step Installation Instructions

Open the Lua Scripting Tool

Launch Mesen 2.1.1 and load your SNES ROM. In the top menu bar, click on Debug / Script Window or Ctrl+N.

In the Lua Scripts window, click File -> New (or clear out any existing placeholder text).

Paste the following script and save it to reuse it for future uses.

-- Mesen 2.1.1 SNES Buffered Memory Monitor Script
-- Stores all incoming characters and prints the full string only when 0 is written

local TARGET_ADDRESS = 0x0021FC
local char_buffer = "" -- Temporary storage for the incoming characters

function on_memory_write(address, value)
    if value == 10 then
        -- Value 10 received! Print the accumulated string if it's not empty
        if #char_buffer > 0 then
            emu.log(char_buffer)
            char_buffer = "" -- Clear the buffer for the next message
        else
            emu.log("[Empty String Received (0)]")
        end
    else
        -- Store the character if it's printable, otherwise log it as hex in the string
        if (value >= 32 and value <= 126) or value == 13 then
            char_buffer = char_buffer .. string.char(value)
        else
            -- Formats non-printable bytes cleanly inside the text stream
            char_buffer = char_buffer .. string.format("[%02X]", value)
        end
    end
end

-- Register the precise write callback
emu.addMemoryCallback(on_memory_write, emu.callbackType.write, TARGET_ADDRESS, TARGET_ADDRESS, emu.memType.snesCpu)

-- Print initialization message to the Log Window
emu.log("Log messages active. Gathering characters from here from $0021FC...")

Run the Script

Click Script -> Run Script (or simply press F5 on your keyboard).

You should instantly see the initial message in the console section of that window: Log messages active. Gathering characters from here from $0021FC...

log_mesen_tut01

Clone this wiki locally