Mesen/Docs/content/apireference/MemoryAccess.md
Zorchenhimer bca96de531 Debugger: Lua - Add new getLabelAddress() function
This adds a new function GetLabelAddress() to the Lua API.  It takes a
single string parameter of a label to lookup and returns its integer
address.  The return value can be passed directly to read() and
readWord().

The documentation has also been updated to reflect the changes.
2018-12-28 12:01:26 -05:00

3.5 KiB

title weight pre chapter
Memory Access 30 false

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.

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.

getLabelAddress

Syntax

emu.getLabelAddress(label)

Parameters
label - String A label to look up.

Return value
Integer The corresponding integer address.

Description
Returns an integer representing the address of the specified label. The return value can be passed directly to read() and readWord().