-
Notifications
You must be signed in to change notification settings - Fork 431
MelonDS System Bus #4555
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
base: master
Are you sure you want to change the base?
MelonDS System Bus #4555
Conversation
…mentations, letting the hooked function decide how to handle them.
…and update SafeToPeek. This makes most things readable and writable from BizHawk. Resolves TASEmulators#3121 except for the problematic addresses listed in SafeToPeek.
This is very much the wrong way to do it. If I'm specifying a bulk read of multiple bytes (e.g. memory.read_bytes_as_array), the behavior shouldn't change just because I decided to read a different amount or depending on where I decided to start the read. Byte at address X returns what address X has when you peek that byte with PeekByte.
They can, there are a ton of lua functions specifically for this.
They can, MemoryDomain does have such functions (that's the entire point of the different poke functions).
You don't need new domains, the function hook just needs to be modified to specify access size and that access size must be sent over for the core to understand how to read/write things. Ideally different widths shouldn't be changing results in the first place, but the System Bus is inherently quirky to the console (since it is more or less native bus reads), so if different widths change results those are arguably just system quirks which are inherent to the System Bus domain, so under that logic it's acceptable for System Bus domains. |
Just to be clear - for the vast majority of addresses, the behavior does not change depending on alignment or number of bytes read.
With the current implementation
I didn't want to try modifying every other core that uses function hooks. Although I suppose it could instead be a second kind of function hook. I could do that. And if we do it this way, the Lua bulk read functions could similarly have a parameter for access size. And corresponding C# API functions...? There's already
Yes, that is my view. IMO there should also be a way to perform system bus reads that have side effects. Maybe this could be accomplished with a new API method that enables read side effects. Making read side effects opt-in would protect users from accidentally causing desyncs. |
|
The first one I will look at later. I don't see the relevance of the second, nor would I wish to attempt to implement it in the near future. |
This PR allows access to 16-bit and 32-bit reads/writes on the system bus domains for melonDS, resolving the issue I had with #3121. This is done in 2 parts:
WaterboxMemoryDomainFuncimplementations for 16 and 32 bit reads and writes, and a bulk byte write implementation. (This requires givingMemoryDomaina bulk byte write, which was taken fromMemoryAPI.)Performance is slightly improved by using larger access sizes inside melon.
This does not give a way to specify to waterbox function hook domains the write size to use. MelonDS will now infer it. Calls to
PeekUintandPokeUintwill use 16-bit access if the address is 2-byte aligned, similar for 32-bit. This results in different behavior compared to letting the user directly specify it in two ways:These behaviors seem acceptable to me.
Another option would be to provide new function hook domains for 16 and 32 bit access. This would grant the user the ability to choose the access size by using one of the 4-6 new "ARMX System Bus XX-bit" domains. This would solve both above issues, but I'm not sure if this would be a better or worse user experience. It would at least hint to users that there is a meaningful difference, which most will not be aware of without being told.
This option would mean the updates to C# code are unnecessary.
I did not want to modify the system bus domains to peek/poke currently unsupported addresses for two reasons.
Regarding hex editor, I don't think there are any great solutions. With this PR, access size in hex editor can be controlled by changing the viewed data size. This is not intuitive. Using sized system bus domains would require the user to change domains, and also leads to the question of what should be done if the user writes a single byte in 1-byte data size mode, to a 32-bit domain? I guess this would have to first read the relevant 4 bytes, change the one byte, then write 4 bytes again. Fortunately, none of this matters for the vast majority of addresses so it's probably not very important as long as it is possible to perform sized access.
Check if completed: