Lua API reference on Mesen Documentation/apireference.htmlRecent content in Lua API reference on Mesen DocumentationHugo -- gohugo.ioen-usChangelog/apireference/changelog.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/changelog.htmlChanges between 0.9.7 and 0.9.8 New Features New function to get a label’s current CPU address: getLabelAddress Changes between 0.9.6 and 0.9.7 No changes. Changes between 0.9.5 and 0.9.6 New Features New event callback: scriptEnded. New functions to get PRG/CHR ROM offsets based on a CPU/PPU address: getPrgRomOffsetand getChrRomOffset. New function for use with the test runner mode: stop Changes The end address parameter for addMemoryCallbackand removeMemoryCallbackis now optional.Callbacks/apireference/callbacks.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/callbacks.htmladdEventCallback Syntax emu.addEventCallback(function, type) Parameters function - A Lua function. type - Enum See eventType. Return value Returns an integer value that can be used to remove the callback by calling removeEventCallback. Description Registers a callback function to be called whenever the specified event occurs. The callback function receives no parameters. removeEventCallback Syntax emu.removeEventCallback(reference, type) Parameters reference - The value returned by the call to addEventCallback. type - Enum See eventType.Drawing/apireference/drawing.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/drawing.htmlDrawing basics All drawing-related functions share a few properties: (x, y) coordinates must be between (0, 0) and (255, 239) The “duration” is specified as a number of frames during which the drawing must remain on the screen. This defaults to 1 frame when unspecified, and draw calls will be permanent (until a call to clearScreen) if duration is set to 0. Colors are integers in ARGB format:Emulation/apireference/emulation.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/emulation.htmlgetState Syntax emu.getState() Return value Table Current emulation state with the following structure: region: int, clockRate: int, cpu: { status: int, a: int, irqFlag: int, cycleCount: int (64-bit, unsigned), pc: int, y: int, x: int, sp: int, nmiFlag: bool }, ppu: { cycle: int, scanline: int, frameCount: int, control: { backgroundEnabled: bool, intensifyBlue: bool, intensifyRed: bool, backgroundPatternAddr: int, grayscale: bool, verticalWrite: bool, intensifyGreen: bool, nmiOnVBlank: bool, spritesEnabled: bool, spritePatternAddr: int, spriteMask: bool, largeSprites: bool, backgroundMask: bool }, status: {, spriteOverflow: bool, verticalBlank: bool, sprite0Hit: bool }, state: { status: int, lowBitShift: int, xScroll: int, highBitShift: int, videoRamAddr: int, control: int, mask: int, tmpVideoRamAddr: int, writeToggle: bool, spriteRamAddr: int } }, apu: { square1: { outputVolume: int, frequency: float, duty: int, period: int, enabled: bool, dutyPosition: int, sweepShift: int, sweepPeriod: int, sweepEnabled: bool, sweepNegate: bool envelope: { counter: int, loop: bool, divider: int, volume: int, startFlag: bool, constantVolume: bool }, lengthCounter: { halt: bool, counter: int, reloadValue: int } }, square2: { outputVolume: int, frequency: float, duty: int, period: int, enabled: bool, dutyPosition: int, sweepShift: int, sweepPeriod: int, sweepEnabled: bool, sweepNegate: bool, envelope: { counter: int, loop: bool, divider: int volume: int, startFlag: bool, constantVolume: bool }, lengthCounter: { halt: bool, counter: int, reloadValue: int } }, triangle: { outputVolume: int, frequency: float, sequencePosition: int, period: int, enabled: bool, lengthCounter: { halt: bool, counter: int, reloadValue: int } }, noise: { modeFlag: bool, enabled: bool, outputVolume: int, frequency: float, period: int, shiftRegister: int, envelope: { counter: int, loop: bool, divider: int, volume: int, startFlag: bool, constantVolume: bool }, lengthCounter: { halt: bool, counter: int, reloadValue: int } }, dmc: { sampleLength: int, irqEnabled: bool, loop: bool, outputVolume: int, bytesRemaining: int, sampleAddr: int, period: int, sampleRate: float }, frameCounter: { fiveStepMode: int, irqEnabled: int, sequencePosition: int } }, cart: { selectedPrgPages: array, chrRomSize: int, chrRamSize: int, prgPageCount: int, chrPageSize: int, selectedChrPages: array, chrPageCount: int, prgRomSize: int, prgPageSize: int, } DescriptionInput/apireference/input.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/input.htmlgetInput Syntax emu.getInput(port) Parameters port - Integer The port number to read (0 to 3) Return value Table A table containing the status of all 8 buttons. Description Returns a table containing the status of all 8 buttons: { a, b, select, start, up, down, left, right } setInput Syntax emu.setInput(port, input) Parameters port - Integer The port number to apply the input to (0 to 3) input - Table A table containing the state of some (or all) of the 8 buttons (same format as returned by getInput)Logging/apireference/logging.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/logging.htmldisplayMessage Syntax emu.displayMessage(category, text) Parameters category - String The category is the portion shown between brackets [] text - String Text to show on the screen Return value None Description Displays a message on the main window in the format “[category] text” log Syntax emu.log(text) Parameters text - String Text to log Return value None Description Logs the given string in the script’s log window - useful for debugging scripts.Memory Access/apireference/memoryaccess.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/memoryaccess.htmlread / readWord Syntax emu.read(address, type, signed = false) emu.readWord(address, type, signed = false) Parameters address - Integer The address/offset to read from. type - Enum The type of memory to read from. See memType. signed - (optional) Boolean If true, the value returned will be interpreted as a signed value. Return value An 8-bit (read) or 16-bit (readWord) value. Description Reads a value from the specified memory type.Miscellaneous/apireference/misc.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/misc.htmlSave States There are 2 separate save state APIs. The first one is synchronous and uses the saveSavestate and loadSavestate functions. Its main restriction is that it can only be used inside “startFrame” or “cpuExec” callback functions. The second API is asynchronous and uses an internally-managed “save slot” system to hold states in memory. It uses the following functions: saveSavestateAsync, loadSavestateAsync, getSavestateData and clearSavestateData. saveSavestate Syntax emu.saveSavestate() Return valueEnums/apireference/enums.htmlMon, 01 Jan 0001 00:00:00 +0000/apireference/enums.htmleventType Syntax emu.eventType.[value] Values reset = 0, Triggered when a soft reset occurs nmi = 1, Triggered when an nmi occurs irq = 2, Triggered when an irq occurs startFrame = 3, Triggered at the start of a frame (cycle 0, scanline -1) endFrame = 4, Triggered at the end of a frame (cycle 0, scanline 240) codeBreak = 5, Triggered when code execution breaks (e.g due to a breakpoint, etc.