Baekalfen / PyBoy

Game Boy emulator written in Python
Other
4.57k stars 472 forks source link

Force clock value #328

Closed debnet closed 3 months ago

debnet commented 3 months ago

Correct me if I'm wrong, but I believe PyBoy supports internal clock with MBC3 cardriges.

Is it possible to force and freeze clock value in a simple way for testing purposes?

I read something about editing memory at specific offsets but alas with no success. https://gbdev.io/pandocs/MBC3.html#the-clock-counter-registers

Thanks!

Baekalfen commented 3 months ago

There is no way of doing that atm.

What do you want to use it for? Maybe we should add it.

Baekalfen commented 3 months ago

If you follow the documentation you sent, you can change the Real Time Clock (RTC). But you'll have to repeatedly set it

Edit: Ok, maybe not

debnet commented 3 months ago

There is no way of doing that atm.

What do you want to use it for? Maybe we should add it.

I'm using PyBoy with my students in reinforcement learning course, and we are using Pokemon Gold/Crystal. We need to have the clock to be the same for all students whenever they decide to run their model on the game because some events ingame are tied to the ingame clock.

Baekalfen commented 3 months ago

I've introduced a PR which should help. When the students start a game for the first time, they'll tell the game what they want their time to be (i.e. Sunday, 3:25PM). This is in reference to the internal counter in the emulation. What I've added, is the option to always have the internal counter be 0 on all values. This should keep the in-game time from changing.

I also found some other RTC bugs, and I'm surprised it even worked before.

debnet commented 3 months ago

Could be glorious to have it editable during runtime. Is it possible? Thank you!

Baekalfen commented 3 months ago

Could be glorious to have it editable during runtime. Is it possible? Thank you!

It's not something I can consistently control from the emulator across games.

I'd say you have some options:

  1. Hack the registers like this: https://github.com/Baekalfen/PyBoy/blob/305efae1a118cb9f4cba8f381346c79b793408fa/tests/test_external_api.py#L45-L63
  2. Make a routine in the game menus to change the time (is there a setting in the menu?)
  3. ROM hacking, overriding the function and return the desired time https://github.com/Baekalfen/PyBoy/blob/183bf9d3d13f1a740f414be5bb5af46f4576fcd4/pyboy/plugins/game_wrapper_tetris.py#L227-L247 https://github.com/pret/pokegold/blob/0d3575ce8e47bd1c70336bff8261257abf92b1dc/engine/rtc/rtc.asm
Baekalfen commented 3 months ago

Could be glorious to have it editable during runtime. Is it possible? Thank you!

This:

they'll tell the game what they want their time to be

Is the game asking, not PyBoy

Baekalfen commented 3 months ago

I'm using PyBoy with my students in reinforcement learning course

Would you be able to share your course material with me? We can do it privately, I just wanted to try experimenting with RL myself.