DeSmuME_Memory - R/W access to the DS memory¶
- class desmume.emulator.DeSmuME_Memory(emu: DeSmuME)[source]¶
Bases:
objectAccess and manipulate the memory of the emulator. Should not be instantiated manually!
- get_next_instruction() int[source]¶
Returns the next instruction to be executed by the ARM9 processor.
- read(start: int, end: int, size: int, signed: bool) int | bytes | List[int][source]¶
Read part of NDS memory. You probably don’t want to use this. Use the
unsignedandsignedproperties instead.Allowed sizes: 1 = byte, 2 = short, 4 = long
If start and end are equal, returns an integer based on the size and the signed flag.
If not, but size is 1 and signed is False, returns a bytes object with all bytes between start and end. Otherwise returns a list of ints based on size and signed.
- read_string(address: int, codec='windows-1255')[source]¶
Read a null-terminated string, beginning at address.
- property register_arm7: RegisterAccessor¶
ARM7 Registers.
- Type:
- property register_arm9: RegisterAccessor¶
ARM9 Registers.
- Type:
- register_exec(address: int, callback: Callable[[int, int], None] | None, size=2)[source]¶
Add a memory callback for when the PC processed the operation at the specified address.
Setting a callback will override the previously registered one for this address. Set callback to None, to remove the callback for this address.
Example (will print ‘Hello World’, whenever the PC executes the code at 0x022f8818):
>>> def my_callback(address, size): >>> print("Hello World!") >>> >>> DeSmuME().memory.register_exec(0x022f8818, my_callback)
- Parameters:
address – The address to monitor.
callback – This callback will be called when the operation was executed. See
MemoryCbFn.size – Leave this at 2.
- register_read(address: int, callback: Callable[[int, int], None] | None, size=1)[source]¶
Add a memory callback for when the memory at the specified address was read.
Setting a callback will override the previously registered one for this address. Set callback to None, to remove the callback for this address.
A usage example can be found for
register_exec.- Parameters:
address – The address to monitor.
callback – This callback will be called when the memory was read. See
MemoryCbFn.size – The maximum size that will be watched. If you set this to 4 for example, a range of (address, address + 3) will be monitored.
- register_write(address: int, callback: Callable[[int, int], None] | None, size=1)[source]¶
Add a memory callback for when the memory at the specified address was changed.
Setting a callback will override the previously registered one for this address. Set callback to None, to remove the callback for this address.
A usage example can be found for
register_exec.- Parameters:
address – The address to monitor.
callback – This callback will be called when the memory was written to. See
MemoryCbFn.size – The maximum size that will be watched. If you set this to 4 for example, a range of (address, address + 3) will be monitored.
- set_next_instruction(address: int)[source]¶
Sets the next instruction to be executed by the ARM9 processor. You should probably also consider updating the PC.
- property signed: MemoryAccessor¶
The accessor for accessing the memory values as signed ints.
- Type:
- property unsigned: MemoryAccessor¶
The accessor for accessing the memory values as raw unsigned bytes/ints.
- Type:
- write(start: int, end: int, size: int, value: bytes | List[int])[source]¶
Write part of NDS memory. You probably don’t want to use this. Use the
unsignedandsignedproperties instead, or thewrite_*methods.
- write_byte(addr: int, value: int)[source]¶
Write a 1-byte integer to the memory at the specified address.