Registering a hook to change PC to the previous instruction doesn't properly advance 'tick'
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 539
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 5
Description
While trying to see if I could emulate breakpoint behavior in PyBoy using hooks, I found that setting the hook to one instruction ahead and changing PC to the instruction I actually wanted to hook was causing tick to never return.
Specifically, in my disassembly of Medarot 3:
```
from pyboy import PyBoy
def breakpoint(p):
p.register_file.PC = p.symbol_lookup("Main.mainGameLoop")[1]
pyboy = PyBoy('medarot3_kabuto.gbc', symbols='medarot3_kabuto.sym')
pyboy.hook_register(0, pyboy.symbol_lookup("Main.mainGameLoop")[1] + 1, breakpoint, pyboy)
pyboy.tick(100)
```
where Main.mainGameLoop is defined as:
```
xor a
ld [$c4d9], a
call Function
...
```
If I instead opt to have my breakpoint at +4 (at the call instead), tick seems to properly return.
This Tick behavior seems to be unintended or undefined, but if it is intended, then I think it would be useful to have it documented.
Contributor guide
Research direction
Start by reproducing the provided Medarot 3 example using hook_register, symbol_lookup, register_file.PC, and tick(100). Trace how tick handles a hook that moves PC to the previous instruction, compare it with the +4 call case, and establish the expected termination behavior. Done means tick returns reliably or the behavior is documented if it is intentional.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100