1--This is an example script to give a general idea of how to build scripts 2--Press F5 or click the Run button to execute it 3--Scripts must be written in Lua (https://www.lua.org) 4--This text editor contains an auto-complete feature for all Mesen-specific functions 5--Typing "emu." will display a list containing every available API function to interact with Mesen 6 7function printInfo() 8 --Get the emulation state 9 state = emu.getState() 10 11 --Get the mouse's state (x, y, left, right, middle) 12 mouseState = emu.getMouseState() 13 14 --Select colors based on whether the left button is held down 15 if mouseState.left == true then 16 for y = 0, 239 do 17 for x = 0, 255 do 18 --Remove red color from the entire screen (slow) 19 color = emu.getPixel(x, y) 20 emu.drawPixel(x, y, color & 0xFFFF, 1) 21 end 22 end 23 bgColor = 0x30FF6020 24 fgColor = 0x304040FF 25 else 26 bgColor = 0x302060FF 27 fgColor = 0x30FF4040 28 end 29 30 --Draw some rectangles and print some text 31 emu.drawRectangle(8, 8, 128, 24, bgColor, true, 1) 32 emu.drawRectangle(8, 8, 128, 24, fgColor, false, 1) 33 emu.drawString(12, 12, "Frame: " .. state.ppu.frameCount, 0xFFFFFF, 0xFF000000, 1) 34 emu.drawString(12, 21, "CPU Cycle: " .. state.cpu.cycleCount, 0xFFFFFF, 0xFF000000, 1) 35 36 emu.drawRectangle(8, 218, 193, 11, bgColor, true, 1) 37 emu.drawRectangle(8, 218, 193, 11, fgColor, false, 1) 38 emu.drawString(11, 220, "Hold left mouse button to switch colors", 0xFFFFFF, 0xFF000000, 1) 39 40 --Draw a block behind the mouse cursor - leaves a trail when moving the mouse 41 emu.drawRectangle(mouseState.x - 2, mouseState.y - 2, 5, 5, 0xAF00FF90, true, 20) 42 emu.drawRectangle(mouseState.x - 2, mouseState.y - 2, 5, 5, 0xAF000000, false, 20) 43end 44 45--Register some code (printInfo function) that will be run at the end of each frame 46emu.addEventCallback(printInfo, emu.eventType.endFrame) 47 48--Display a startup message 49emu.displayMessage("Script", "Example Lua script loaded.") 50