Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory.registerwrite #30

Closed
GoogleCodeExporter opened this issue Jun 22, 2015 · 2 comments
Closed

memory.registerwrite #30

GoogleCodeExporter opened this issue Jun 22, 2015 · 2 comments
Labels
re: Lua API/scripting Relating to EmuHawk's Lua API (not the Lua Console)

Comments

@GoogleCodeExporter
Copy link

Add memory.registerwrite to the Lua implementation. Presumably would be the 
same concept as it is in FCEUX:

memory.registerwrite(int address, [int size,] function func)

Registers a function to be called immediately whenever the given memory address 
range is written to.

size is the number of bytes to "watch". For example, if size is 100 and address 
is 0x0200, then you will register the function across all 100 bytes from 0x0200 
to 0x0263. A write to any of those bytes will trigger the function. Having 
callbacks on a large range of memory addresses can be expensive, so try to use 
the smallest range that's necessary for whatever it is you're trying to do. If 
you don't specify any size then it defaults to 1.

The callback function will receive two arguments, (address, size) indicating 
what write operation triggered the callback. If you don't care about that extra 
information then you can ignore it and define your callback function to not 
take any arguments. The value that was written is NOT passed into the callback 
function, but you can easily use any of the memory.read functions to retrieve 
it.

You may use a memory.write function from inside the callback to change the 
value that just got written. However, keep in mind that doing so will trigger 
your callback again, so you must have a "base case" such as checking to make 
sure that the value is not already what you want it to be before writing it. 
Another, more drastic option is to de-register the current callback before 
performing the write.

If func is nil that means to de-register any memory write callbacks that the 
current script has already registered on the given range of bytes.

Original issue reported on code.google.com by brandman...@gmail.com on 12 May 2012 at 5:30

@GoogleCodeExporter
Copy link
Author

This has been implemented as event.onmemorywrite()

Original comment by adeli...@tasvideos.org on 20 Oct 2012 at 10:52

@GoogleCodeExporter
Copy link
Author

Original comment by adeli...@tasvideos.org on 20 Oct 2012 at 10:52

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: Lua API/scripting Relating to EmuHawk's Lua API (not the Lua Console)
Projects
None yet
Development

No branches or pull requests

2 participants