Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Mesen Lua 函数库.
- Mesen Lua API reference
- Important: This API is similar but not completely compatible with the old Mesen 0.9.x (or Mesen-S) Lua APIs.
- Generated on Sep 6 2024, 08:54:50 for Mesen 2.0.0.
- Callbacks
- addEventCallback
- Syntax
- emu.addEventCallback(callback, eventType)
- Parameters
- callback - Function
- Lua function to call when the event occurs
- eventType - Enum (eventType)
- Event type
- Return value
- Int - Value that can be used to remove the callback by calling emu.removeEventCallback().
- Description
- Registers a callback function to be called whenever the specified event occurs.
- The callback function receives 1 parameter ("cpuType") which is an enum value (emu.cpuType) which indicates which CPU triggered the event (useful to distinguish between identical events triggered by different CPUs, e.g Super Game Boy).
- addMemoryCallback
- Syntax
- emu.addMemoryCallback(callback, callbackType, startAddress, endAddress, cpuType, memoryType)
- Parameters
- callback - Function
- Lua function to call when the event occurs
- callbackType - Enum (callbackType)
- Callback type
- startAddress - Int
- Start of the address range
- endAddress - Int (default: start address)
- End of the address range
- cpuType - Enum (cpuType) (default: main CPU)
- CPU used for the callback
- memoryType - Enum (memType) (default: main CPU memory)
- Memory type for the callback
- Return value
- Int - Value that can be used to remove the callback by calling emu.removeMemoryCallback().
- Description
- Registers a callback function to be called whenever the specified event occurs.
- The callback function receives 2 parameters ("address" and "value") that correspond to the address being written to or read from, and the value that is being read/written.
- For reads, the callback is called after the read is performed.
- For writes, the callback is called before the write is performed.
- If the callback returns an integer value, it will replace the value - you can alter the results of read/write operation by using this.
- removeEventCallback
- Syntax
- emu.removeEventCallback(reference, eventType)
- Parameters
- reference - Int
- Value returned by the call to emu.addEventCallback()
- eventType - Enum (eventType)
- Event type
- Return value
- <none>
- Description
- Removes a previously registered callback function.
- removeMemoryCallback
- Syntax
- emu.removeMemoryCallback(reference, callbackType, startAddress, endAddress, cpuType, memoryType)
- Parameters
- reference - Int
- Value returned by the call to emu.addMemoryCallback()
- callbackType - Enum (callbackType)
- Callback type
- startAddress - Int
- Start of the address range
- endAddress - Int (default: start address)
- End of the address range
- cpuType - Enum (cpuType) (default: main CPU)
- CPU used for the callback
- memoryType - Enum (memType) (default: main CPU memory)
- Memory type
- Return value
- <none>
- Description
- Removes a previously registered callback function.
- Drawing
- clearScreen
- Syntax
- emu.clearScreen()
- Parameters
- <none>
- Return value
- <none>
- Description
- Removes all drawn shapes from the screen.
- drawLine
- Syntax
- emu.drawLine(x, y, x2, y2, color, duration, delay)
- Parameters
- x - Int
- X position (start of line)
- y - Int
- Y position (start of line)
- x2 - Int
- X position (end of line)
- y2 - Int
- Y position (end of line)
- color - Int (ARGB) (default: 0xFFFFFF (white))
- Color
- duration - Int (default: 1)
- Number of frames to display
- delay - Int (default: 0)
- Number of frames to wait before drawing the line
- Return value
- <none>
- Description
- Draws a line between (x, y) to (x2, y2) using the specified color for a specific number of frames.
- drawPixel
- Syntax
- emu.drawPixel(x, y, color, duration, delay)
- Parameters
- x - Int
- X position
- y - Int
- Y position
- color - Int (ARGB)
- Color
- duration - Int (default: 1)
- Number of frames to display
- delay - Int (default: 0)
- Number of frames to wait before drawing the pixel
- Return value
- <none>
- Description
- Draws a pixel at the specified (x, y) coordinates using the specified color for a specific number of frames.
- drawRectangle
- Syntax
- emu.drawRectangle(x, y, width, height, color, fill, duration, delay)
- Parameters
- x - Int
- X position
- y - Int
- Y position
- width - Int
- Width
- height - Int
- Height
- color - Int (ARGB) (default: 0xFFFFFF (white))
- Color
- fill - Boolean (default: false)
- Whether or not to draw an outline, or a filled rectangle.
- duration - Int (default: 1)
- Number of frames to display
- delay - Int (default: 0)
- Number of frames to wait before drawing the rectangle
- 重试
- 错误原因
- Return value
- <none>
- Description
- Draws a rectangle between (x, y) to (x+width, y+height) using the specified color for a specific number of frames. If fill is false, only the rectangle's outline will be drawn.
- drawString
- Syntax
- emu.drawString(x, y, text, textColor, backgroundColor, maxWidth, duration, delay)
- Parameters
- x - Int
- X position
- y - Int
- Y position
- text - String
- Text to display
- textColor - Int (ARGB) (default: 0xFFFFFF (white))
- Color to use for the text
- backgroundColor - Int (ARGB) (default: 0 (transparent))
- Color to use for the background
- maxWidth - Int (default: 0)
- 重试
- 错误原因
- Max width (pixels) - wraps to next line when reached
- duration - Int (default: 1)
- Number of frames to display
- delay - Int (default: 0)
- Number of frames to wait before drawing the text
- Return value
- <none>
- Description
- Draws text at (x, y) using the specified text and colors for a specific number of frames.
- getDrawSurfaceSize
- Syntax
- emu.getDrawSurfaceSize(surface)
- Parameters
- surface - Enum (drawSurface) (default: current draw surface)
- Draw surface
- Return value
- Table - { width = int, height = int, visibleWidth = int, visibleHeight = int, overscan = { top = int, bottom = int, left = int, right = int } }
- Description
- Returns a table containing the full size, visible size and overscan size for the selected draw surface.
- 重试
- 错误原因
- getPixel
- Syntax
- emu.getPixel(x, y)
- Parameters
- x - Int
- 重试
- 错误原因
- X position
- y - Int
- Y position
- Return value
- Int - ARGB color
- Description
- Returns the color (in ARGB format) of the screen's output for the specified coordinates.
- getScreenBuffer
- Syntax
- emu.getScreenBuffer()
- Parameters
- <none>
- Return value
- Array - Array of ARGB values
- Description
- Returns an array of ARGB values with the contents of the console's screen - can be used with emu.setScreenBuffer() to modify the screen's contents.
- Note: The size of the array varies based on the console, game, and sometimes scene. Use emu.getScreenSize() to get the screen's current dimensions.
- getScreenSize
- Syntax
- emu.getScreenSize()
- Parameters
- <none>
- Return value
- Table - { width = int, height = int }
- Description
- Returns a table containing the size of the console's current screen output.
- measureString
- Syntax
- emu.measureString(text, maxWidth)
- Parameters
- text - String
- String to measure
- maxWidth - Int (default: 0)
- Max width (pixels) - wraps to next line when reached
- Return value
- Table - { width = int, height = int }
- Description
- Measures the specified string and returns a table containing the width and height that the string would take when drawn.
- selectDrawSurface
- Syntax
- emu.selectDrawSurface(surface, scale)
- Parameters
- surface - Enum (drawSurface)
- Draw surface
- scale - Int (default: current scale)
- Scale to use for the "scriptHud" surface (max: 4)
- Return value
- <none>
- 重试
- 错误原因
- Description
- Selects the surface on which any subsequent draw call will be drawn to.
- consoleScreen: This surface is the same as the console's output and is a fixed resolution. Anything drawn here will appear in screenshots/videos.
- scriptHud: This surface is independent to the console's output and has a configurable resolution. Drawings done on this surface will not appear in screenshots/videos.
- Note: setScreenBuffer always draws to the "consoleScreen" surface.
- setScreenBuffer
- Syntax
- emu.setScreenBuffer(screenBuffer)
- Parameters
- screenBuffer - Array
- Array of integers in ARGB format
- Return value
- <none>
- Description
- Replaces the current frame with the contents of the specified array.
- Emulation
- breakExecution
- Syntax
- emu.breakExecution()
- Parameters
- <none>
- Return value
- <none>
- Description
- Breaks the execution.
- getState
- Syntax
- emu.getState()
- Parameters
- <none>
- Return value
- Table - Content varies for each console and game.
- Description
- Returns a table containing key-value pairs that describe the console's current state.
- Note: The name of the values returned may change from one version to another. Some values may represent the emulator's internal state and may not be useful (these will be hidden in future versions.)
- reset
- Syntax
- emu.reset()
- Parameters
- <none>
- Return value
- <none>
- Description
- Resets the current game. If the console does not have a reset button, this will have the same effect as power cycling.
- resume
- Syntax
- emu.resume()
- Parameters
- 重试
- 错误原因
- <none>
- Return value
- <none>
- Description
- Resumes execution after a break.
- rewind
- Syntax
- emu.rewind(seconds)
- Parameters
- seconds - Int
- Number of seconds to rewind
- Return value
- <none>
- Description
- Instantly rewinds the emulation by the number of seconds specified.
- Note: This can only be called from inside an "exec" memory callback.
- setState
- Syntax
- emu.setState(state)
- Parameters
- state - Table
- A key-value table containing the state to be applied.
- Return value
- <none>
- Description
- Changes the state of the emulator to match the values provided in the "state" parameter.
- Note: The name of the values returned may change from one version to another. Some values may represent the emulator's internal state and should not be changed (access to these will be removed in future versions.)
- step
- Syntax
- emu.step(count, stepType, cpuType)
- Parameters
- count - Int
- Number of cycles/frames/etc.
- stepType - Enum (stepType)
- Step type
- cpuType - Enum (cpuType) (default: main CPU)
- CPU type
- Return value
- <none>
- Description
- Breaks the emulation's execution when the step conditions are reached.
- stop
- Syntax
- emu.stop(exitCode)
- Parameters
- exitCode - Int
- The exit code that the Mesen process will return.
- Return value
- <none>
- Description
- Stops the emulation and returns the specified exit code (when used with the --testRunner command line option).
- Input
- getInput
- Syntax
- emu.getInput(port, subPort)
- Parameters
- port - Int
- Port number
- subPort - Int (default: 0)
- Subport number - this is used for multitap-like adapters.
- Return value
- Table - Content varies based on controller type.
- Description
- Returns a table containing the state of all buttons for the selected port/controller. The table's content varies based on the controller type.
- getMouseState
- Syntax
- emu.getMouseState()
- Parameters
- <none>
- Return value
- Table - { x = int, y = int, relativeX = int, relativeY = int, left = bool, middle = bool, right = bool }
- Description
- Returns a table containing the position and the state of all 3 buttons.
- isKeyPressed
- Syntax
- emu.isKeyPressed(keyName)
- Parameters
- keyName - String
- Name of the key to check
- Return value
- Bool - The key's state (true when pressed)
- Description
- Returns whether or not a specific key is pressed. The "keyName" must be the same as the string shown in the UI when the key is bound to a button.
- setInput
- Syntax
- emu.setInput(input, port, subPort)
- Parameters
- input - Table
- Controller state to apply to the port, same format as the return value of getInput().
- port - Int
- Port number
- subPort - Int (default: 0)
- Subport number - this is used for multitap-like adapters.
- Return value
- <none>
- Description
- Sets the input state for the specified port. Buttons enabled or disabled via setInput will keep their state until the next inputPolled event.
- Note: If a button's value is not specified in the "input" argument, then the player retains control of that button. For example, "emu.setInput({ select = false, start = false }, 0)" will prevent the player 1 from using both the start and select buttons, but all other buttons will still work as normal.
- It is recommended to use this function within a callback for the inputPolled event. Otherwise, the inputs may not be applied before the ROM has the chance to read them.
- Logging
- displayMessage
- 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"
- getLogWindowLog
- Syntax
- emu.getLogWindowLog()
- Parameters
- <none>
- Return value
- String - A string containing the log shown in the log window
- Description
- Returns the same text as what is shown in the emulator's log window.
- log
- Syntax
- emu.log(text)
- Parameters
- text - String
- Text to log
- Return value
- <none>
- Description
- Logs the specified string in the script's log window - useful for debugging scripts.
- Memory Access
- convertAddress
- Syntax
- emu.convertAddress(address, memoryType, cpuType)
- Parameters
- address - Int
- Address to convert
- memoryType - Enum (memType) (default: main CPU memory)
- Memory type
- cpuType - Enum (cpuType) (default: main CPU)
- CPU used for the conversion
- Return value
- Table - { address = int, memType = enum }
- Description
- Converts an address between CPU addressing mode and ROM/RAM addressing mode.
- When a ROM/RAM address is given, a CPU address matching that value is returned, if the address is mapped.
- When a CPU address is given, the corresponding ROM/RAM address is returned, if the address is mapped to ROM/RAM.
- getLabelAddress
- Syntax
- emu.getLabelAddress(label)
- Parameters
- label - String
- Label
- Return value
- Table - { address = int, memType = int }
- Note: Returns nil when the specified label could not be found.
- Description
- Returns a table containing the address and memory type for the specified label.
- getMemorySize
- Syntax
- emu.getMemorySize(memoryType)
- Parameters
- memoryType - Enum (memType)
- Memory type
- Return value
- Int - Size of the specified memory type
- Description
- Returns the size (in bytes) of the specified memory type.
- read
- Syntax
- emu.read(address, memoryType, signed)
- Parameters
- address - Int
- Address to read from
- memoryType - Enum (memType)
- Memory type to read from
- signed - Bool
- When true, the return value is an 8-bit signed value.
- Return value
- Int - An 8-bit (signed or unsigned) value.
- Description
- Reads an 8-bit value from the specified address and memory type.
- Note: When using "memType.[cpuName]" memory types, side-effects can occur from reading a value. Use the "memType.[cpuName]Debug" enum values to avoid side-effects.
- read16
- Syntax
- emu.read16(address, memoryType, signed)
- Parameters
- address - Int
- Address to read from
- memoryType - Enum (memType)
- Memory type to read from
- signed - Bool
- When true, the return value is a 16-bit signed value.
- Return value
- Int - A 16-bit (signed or unsigned) value.
- Description
- Reads a 16-bit value from the specified address and memory type.
- Note: When using "memType.[cpuName]" memory types, side-effects can occur from reading a value. Use the "memType.[cpuName]Debug" enum values to avoid side-effects.
- read32
- Syntax
- emu.read32(address, memoryType, signed)
- Parameters
- address - Int
- Address to read from
- memoryType - Enum (memType)
- Memory type to read from
- signed - Bool
- When true, the return value is a 32-bit signed value.
- Return value
- Int - A 32-bit (signed or unsigned) value.
- Description
- Reads a 32-bit value from the specified address and memory type.
- Note: When using "memType.[cpuName]" memory types, side-effects can occur from reading a value. Use the "memType.[cpuName]Debug" enum values to avoid side-effects.
- write
- Syntax
- emu.write(address, value, memoryType)
- Parameters
- address - Int
- Address to write to
- value - Int
- 8-bit value to write
- memoryType - Enum (memType)
- Memory type to write to
- Return value
- <none>
- Description
- Writes an 8-bit value to the specified address and memory type.
- Note: When using "memType.[cpuName]" memory types, side-effects can occur from writing a value. Use the "memType.[cpuName]Debug" enum values to avoid side-effects.
- write16
- Syntax
- emu.write16(address, value, memoryType)
- Parameters
- address - Int
- Address to write to
- value - Int
- 16-bit value to write
- memoryType - Enum (memType)
- Memory type to write to
- Return value
- <none>
- Description
- Writes a 16-bit value to the specified address and memory type.
- Note: When using "memType.[cpuName]" memory types, side-effects can occur from writing a value. Use the "memType.[cpuName]Debug" enum values to avoid side-effects.
- write32
- Syntax
- emu.write32(address, value, memoryType)
- Parameters
- address - Int
- Address to write to
- value - Int
- 32-bit value to write
- memoryType - Enum (memType)
- Memory type to write to
- Return value
- <none>
- Description
- Writes a 32-bit value to the specified address and memory type.
- Note: When using "memType.[cpuName]" memory types, side-effects can occur from writing a value. Use the "memType.[cpuName]Debug" enum values to avoid side-effects.
- Miscellaneous
- Access Counters
- getAccessCounters
- Syntax
- emu.getAccessCounters(counterType, memoryType)
- Parameters
- counterType - Enum (counterType)
- Counter type
- memoryType - Enum (memType)
- Memory type
- Return value
- Array - Array of ints
- Description
- Returns an array of access counters for the specified memory and operation types.
- resetAccessCounters
- Syntax
- emu.resetAccessCounters()
- Parameters
- <none>
- Return value
- <none>
- Description
- Resets all access counters.
- Cheats
- addCheat
- Syntax
- emu.addCheat(cheatType, cheatCode)
- Parameters
- cheatType - Enum (cheatType)
- Cheat type/format
- cheatCode - String
- Cheat code
- Return value
- <none>
- Description
- Adds the specified cheat code.
- Note: Cheat codes added via this function are not permanent and not visible in the UI.
- clearCheats
- Syntax
- emu.clearCheats()
- Parameters
- <none>
- Return value
- <none>
- Description
- Removes all active cheat codes.
- Note: This has no impact on cheat codes saved in the UI, but it will disable them temporarily.
- Save States
- createSavestate
- Syntax
- emu.createSavestate()
- Parameters
- <none>
- Return value
- String - Binary string containing the savestate.
- Description
- Creates a savestate and returns it as a binary string.
- Note: This can only be called from inside an "exec" memory callback.
- loadSavestate
- Syntax
- emu.loadSavestate(state)
- Parameters
- state - String
- Binary data containing the savestate
- Return value
- <none>
- Description
- Loads a savestate from a binary string.
- Note: This can only be called from inside an "exec" memory callback.
- Others
- getRomInfo
- Syntax
- emu.getRomInfo()
- Parameters
- <none>
- Return value
- Table - { name = string, path = string, fileSha1Hash = string }
- Description
- Returns information about the ROM file that is currently running.
- getScriptDataFolder
- Syntax
- emu.getScriptDataFolder()
- Parameters
- <none>
- Return value
- String - The folder's path
- Description
- This function returns the path to a unique folder (based on the script's filename) where the script should store its data (if any data needs to be saved). The data will be saved in subfolders inside the LuaScriptData folder in Mesen's home folder.
- Note: This function will return an empty string if the "Allow access to I/O and OS functions" option is disabled.
- takeScreenshot
- Syntax
- emu.takeScreenshot()
- Parameters
- <none>
- Return value
- String - A binary string containing a PNG image.
- Description
- Takes a screenshot and returns a PNG file as a string. The screenshot is not saved to the disk.
- Enums
- callbackType
- Syntax
- emu.callbackType.[value]
- Description
- Used by emu.addMemoryCallback() and emu.removeMemoryCallback()
- Values
- read - Callback is called when data is read
- write - Callback is called when data is written
- exec - Callback is called when the CPU starts executing an instruction
- cheatType
- Syntax
- emu.cheatType.[value]
- Description
- Used by emu.addCheat()
- Values
- nesGameGenie - Game Genie (NES)
- nesProActionRocky - Pro Action Rocky (NES)
- nesCustom - Custom Address:Value code (NES)
- gbGameGenie - Game Genie (GB)
- gbGameShark - Game Shark (GB)
- snesGameGenie - Game Genie (SNES)
- snesProActionReplay - Pro Action Replay (SNES)
- pceRaw - 24-bit address format (PC Engine)
- pceAddress - 21-bit address format (PC Engine)
- smsProActionReplay - Pro Action Replay (SMS)
- smsGameGenie - Game Genie (SMS)
- counterType
- Syntax
- emu.counterType.[value]
- Description
- Used by emu.getAccessCounters()
- Values
- readCount - Returns the number of times each byte was read
- writeCount - Returns the number of times each byte was written
- execCount - Returns the number of times each byte was executed
- lastReadClock - Returns the time at which each byte was last read
- lastWriteClock - Returns the time at which each byte was last written
- lastExecClock - Returns the time at which each byte was last executed
- cpuType
- Syntax
- emu.cpuType.[value]
- Description
- Used by several APIs to specify which CPU the API call applies to.
- Values
- snes - SNES - Main CPU - S-CPU 5A22 (65186)
- spc - SNES - SPC
- necDsp - SNES - DSP-n
- sa1 - SNES - SA-1
- cx4 - SNES - CX4
- gameboy - Game Boy - Main CPU (can also be used in SGB mode)
- nes - NES - Main CPU - 2A03 (6502)
- pce - PC Engine - Main CPU - HuC6280
- sms - SMS - Main CPU - Z80
- gba - GBA - Main CPU - ARM7TDMI
- drawSurface
- Syntax
- emu.drawSurface.[value]
- Description
- Used by emu.selectDrawSurface() and emu.getDrawSurfaceSize()
- Values
- consoleScreen - Console's framebuffer. Drawings appear in screenshots/videos.
- scriptHud - Separate surface with a configurable resolution. Drawings not shown in screenshots/videos.
- eventType
- Syntax
- emu.eventType.[value]
- Description
- Used by emu.addEventCallback() and emu.removeEventCallback()
- Values
- nmi - Triggered when an NMI occurs (not available on some consoles)
- irq - Triggered when an IRQ occurs
- startFrame - Triggered when a frame starts (typically once vertical blank ends)
- endFrame - Triggered when a frame ends (typically once vertical blank starts)
- reset - Triggered when the console is reset (not available on some consoles)
- scriptEnded - Triggered when the Lua script is stopped
- inputPolled - Triggered after the emulator updates the state of all input devices (once per frame)
- stateLoaded - Triggered when a savestate is manually loaded
- stateSaved - Triggered when a savestate is manually saved
- codeBreak - Triggered when code execution breaks (e.g breakpoint, step, etc.)
- memType
- Syntax
- emu.memType.[value]
- Description
- Used by several APIs to specify which memory type to access/use.
- Values
- snesMemory - SNES - S-CPU memory
- spcMemory - SNES - SPC memory
- sa1Memory - SNES - SA-1 memory
- necDspMemory - SNES - DSP-n memory
- gsuMemory - SNES - GSU memory
- cx4Memory - SNES - CX4 memory
- gameboyMemory - Game Boy - CPU memory
- nesMemory - NES - CPU memory
- nesPpuMemory - NES - PPU memory
- pceMemory - PC Engine - CPU memory
- smsMemory - SMS - CPU memory
- gbaMemory - GBA - CPU memory
- snesDebug - SNES - S-CPU memory (no read/write side-effects)
- spcDebug - SNES - SPC memory (no read/write side-effects)
- sa1Debug - SNES - SA-1 memory (no read/write side-effects)
- necDspDebug - SNES - DSP-n memory (no read/write side-effects)
- gsuDebug - SNES - GSU memory (no read/write side-effects)
- cx4Debug - SNES - CX4 memory (no read/write side-effects)
- gameboyDebug - Game Boy - CPU memory (no read/write side-effects)
- nesDebug - NES - CPU memory (no read/write side-effects)
- nesPpuDebug - NES - PPU memory (no read/write side-effects)
- pceDebug - PC Engine - CPU memory (no read/write side-effects)
- smsDebug - SMS - CPU memory (no read/write side-effects)
- gbaDebug - GBA - CPU memory (no read/write side-effects)
- snesPrgRom - SNES - PRG ROM
- snesWorkRam - SNES - Work RAM
- snesSaveRam - SNES - Save RAM
- snesVideoRam - SNES - Video RAM
- snesSpriteRam - SNES - Sprite RAM (OAM)
- snesCgRam - SNES - Palette RAM (CGRAM)
- spcRam - SNES - SPC - RAM
- spcRom - SNES - SPC - IPL ROM
- dspProgramRom - SNES - DSP-n - Program ROM
- dspDataRom - SNES - DSP-n - Data ROM
- dspDataRam - SNES - DSP-n - Data RAM
- sa1InternalRam - SNES - SA-1 - IRAM
- gsuWorkRam - SNES - GSU - Work RAM
- cx4DataRam - SNES - CX4 - Data RAM
- bsxPsRam - SNES - BS-X - PSRAM
- bsxMemoryPack - SNES - BS-X - Memory Pack
- gbPrgRom - Game Boy - PRG ROM
- gbWorkRam - Game Boy - Work RAM
- gbCartRam - Game Boy - Cart/Save RAM
- gbHighRam - Game Boy - High RAM
- gbBootRom - Game Boy - Boot ROM
- gbVideoRam - Game Boy - Video RAM
- gbSpriteRam - Game Boy - Sprite RAM
- nesPrgRom - NES - PRG ROM
- nesInternalRam - NES - System RAM
- nesWorkRam - NES - Work RAM
- nesSaveRam - NES - Save RAM
- nesNametableRam - NES - Nametable RAM (CIRAM)
- nesSpriteRam - NES - Sprite RAM (OAM)
- nesSecondarySpriteRam - NES - Secondary Sprite RAM
- nesPaletteRam - NES - Palette RAM
- nesChrRam - NES - CHR RAM
- nesChrRom - NES - CHR ROM
- pcePrgRom - PC Engine - HuCard ROM
- pceWorkRam - PC Engine - Work RAM
- pceSaveRam - PC Engine - Save RAM
- pceCdromRam - PC Engine - CD-ROM Unit RAM
- pceCardRam - PC Engine - Card RAM
- pceAdpcmRam - PC Engine - ADPCM RAM
- pceArcadeCardRam - PC Engine - Arcade Card RAM
- pceVideoRam - PC Engine - Video RAM (VDC)
- pceVideoRamVdc2 - PC Engine - Video RAM (VDC2 - SuperGrafx only)
- pceSpriteRam - PC Engine - Sprite RAM (VDC)
- pceSpriteRamVdc2 - PC Engine - Sprite RAM (VDC2 - SuperGrafx only)
- pcePaletteRam - PC Engine - Palette RAM (VCE)
- smsPrgRom - SMS - ROM
- smsWorkRam - SMS - System RAM
- smsCartRam - SMS - Cart RAM
- smsBootRom - SMS - BIOS ROM
- smsVideoRam - SMS - Video RAM
- smsPaletteRam - SMS - Palette RAM
- smsPort - SMS - I/O Port
- gbaPrgRom - GBA - ROM
- gbaIntWorkRam - GBA - Internal Work RAM
- gbaExtWorkRam - GBA - External Work RAM
- gbaSaveRam - GBA - Save RAM/Flash/EEPROM
- gbaBootRom - GBA - BIOS ROM
- gbaVideoRam - GBA - Video RAM
- gbaSpriteRam - GBA - Sprite RAM
- gbaPaletteRam - GBA - Palette RAM
- stepType
- Syntax
- emu.stepType.[value]
- Description
- Used by emu.step()
- Values
- step - Steps the specified number of instructions
- stepOut - Steps out of the current subroutine (not available for all CPUs)
- stepOver - Steps over the current subroutine call (not available for all CPUs)
- cpuCycleStep - Steps the specified number of CPU cycles (not available for all CPUs)
- ppuStep - Steps the specified number of scanline cycles
- ppuScanline - Steps the specified number of scanlines
- ppuFrame - Steps the specified number of video frames
- specificScanline - Breaks on the specified scanline number
- runToNmi - Breaks on the next NMI event
- runToIrq - Breaks on the next IRQ event
- --NES游戏似乎不支持read16,read32,write16,write32.
- read / 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.
- When calling read / readWord with the memType.cpu or memType.ppu memory types, emulation side-effects may occur.
- To avoid triggering side-effects, use the memType.cpuDebug or memType.ppuDebug types, which will not cause side-effects.
- write / writeWord
- Syntax
- emu.write(address, value, type)
- emu.writeWord(address, value, type)
- Parameters
- address - Integer The address/offset to write to.
- value - Integer The value to write.
- type - Enum The type of memory to write to. See memType.
- Return value
- None
- Description
- Writes an 8-bit or 16-bit value to the specified memory type.
- Normally read-only types such as PRG-ROM or CHR-ROM can be written to when using memType.prgRom or memType.chrRom.
- Changes will remain in effect until a power cycle occurs.
- To revert changes done to ROM, see revertPrgChrChanges.
- When calling write / writeWord with the memType.cpu or memType.ppu memory types, emulation side-effects may occur.
- To avoid triggering side-effects, use the memType.cpuDebug or memType.ppuDebug types, which will not cause side-effects.
- revertPrgChrChanges
- Syntax
- emu.revertPrgChrChanges()
- Return value
- None
- Description
- Reverts all modifications done to PRG-ROM and CHR-ROM via write/writeWord calls.
- getPrgRomOffset
- Syntax
- emu.getPrgRomOffset(address)
- Parameters
- address - Integer A CPU address (Valid range: $0000-$FFFF)
- Return value
- Integer The corresponding byte offset in PRG ROM
- Description
- Returns an integer representing the byte offset of the specified CPU address in PRG ROM based on the mapper’s current configuration. Returns -1 when the specified address is not mapped to PRG ROM.(Mesen2.x已弃用)
- getChrRomOffset
- Syntax
- emu.getChrRomOffset(address)
- Parameters
- address - Integer A PPU address (Valid range: $0000-$3FFF)
- Return value
- Integer The corresponding byte offset in CHR ROM
- Description
- Returns an integer representing the byte offset of the specified PPU address in CHR ROM based on the mapper’s current configuration. Returns -1 when the specified address is not mapped to CHR ROM.(Mesen2.x已弃用)
- getLabelAddress
- Syntax
- emu.getLabelAddress(label)
- Parameters
- label - String The label to look up
- Return value
- Integer The corresponding CPU address
- Description
- Returns the address of the specified label. This address can be used with the memory read/write functions (read(), readWord(), write(), writeWord()) using the emu.memType.cpu or emu.memType.cpuDebug memory types.
Advertisement