-
Notifications
You must be signed in to change notification settings - Fork 384
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
Value from mem address is not passed to read callback #3813
Comments
I believe that is actually somewhat intentional, as reading data may have side-effects. Also, the lua method documentation for |
Unlike writes, there's not a before and after value—unless you count registers but those are even easier to peek from the callback than memory is. So the value would be populated with the read function's return value as NesHawk does here, or equivalently from a peek (side-effects shouldn't come into this) at BizHawk/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs Lines 1077 to 1084 in b98942d
The other option is to fix the docs to reflect reality. |
Yes I didn't add it in the description, but it might be worth noting that the reason this behavior happens is because when the read memory callback function for each core (BSNES and Genplus-gx) is called, the value 0 is being passed as the value. My point being that as Yoshi says if the value is populated with the read function's return value, I think it should work, since only one read is happening anyway. Here's what I mean: BizHawk/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs Lines 70 to 77 in 6725363
BizHawk/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.cs Lines 323 to 329 in 6725363
As for the docs, I imagine it means before the address is read by the game's code, but not necessarily the core itself. So the way I understand it, whenever the game needs to read from an address, the read memory function is called (ReadMemory for NesHawk), so the game waits for the return value, meaning that until that value is not returned, the address was not read, even though of course it has to be read before by the core to be able to pass it to the game (and to the callback for that matter). I understood it that way the first time I read it, and if that's what it means, then yes it can be confusing, although I am not sure if it would require an update. I am also giving it a try and seeing if I can do the fix myself. You can of course do a |
Well yes, but there's still a before and after state when considering side-effects, so I believe the distinction of before and after still matters. When the docs explicitly specify In that regard I'd definitely appreciate an update to the docs to clarify for both bizhawk devs and lua devs how exactly those functions should work. As it reads currently, calling the callback function before a value was read, but including the read value does not make sense. |
It makes sense from the perspective of the script author: At the time the callback gets execution, the 'current'/'before' state is visible through the APIs, and since the 'future'/'after' state can't easily be reconstructed, the callback is provided those values via the parameters. It just happens that the 'Before' in the internal API contract means before. If the implementation necessitates that the side-effects of a read must happen before or during a read, then the memory callback part will have to include an extra peek. (Or return |
- related to issue TASEmulators#3813 - update signatures, send returned value from bus read as data to read callback
- related to issue TASEmulators#3813 - update signatures, create new value variable in each of the memory read core functions, pass it to the callback and return it instead of the inline calculations. Also, pass val to write and exec callbacks in IDebuggable since they all use the same mem_cb signature and it would break otherwise. I want to update write and exec callbacks in next commit though to ensure nothing unexpected happens.
- related to issue TASEmulators#3813
- related to issue TASEmulators#3813 - update signatures, create new value variable in each of the memory read core functions, pass it to the callback and return it instead of the inline calculations. Also, pass val to write and exec callbacks in IDebuggable since they all use the same mem_cb signature and it would break otherwise. I want to update write and exec callbacks in next commit though to ensure nothing unexpected happens.
- related to issue TASEmulators#3813
- related to issue TASEmulators#3813 - update signatures, send returned value from bus read as data to read callback
- related to issue TASEmulators#3813 - update signatures, create new value variable in each of the memory read core functions, pass it to the callback and return it instead of the inline calculations. Also, pass val to write and exec callbacks in IDebuggable since they all use the same mem_cb signature and it would break otherwise. I want to update write and exec callbacks in next commit though to ensure nothing unexpected happens.
- related to issue TASEmulators#3813
Summary
When running a lua script which registers a memory callback function to the on_bus_read hook, and the core calls the callback function, the value from the memory address is not passed.
So far I found it happens with BSNES and Genplus-gx, but it could potentially happen with other cores as well. Also with every game, for example Virtual Bart (Sega Genesis version, that is core Genplus-gx) and Contra 3: The Alien Wars (for BSNES). Both memory addresses are for the RNG. Contra 3: The Alien Wars' RNG starts advancing as soon as the Konami presentation starts (that is, before the title screen) and Virtual Bart's after the roulette starts spinning (start the game, skip the cutscene, then wait a few moments until the roulette starts spinning, you can also go to the practice area which makes the RNG advance as well).
Repro
Lua script:
Output
The value printed to the console is always 0.
Host env.
The text was updated successfully, but these errors were encountered: