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

[GBA] Enable writing RTC state/saving in save file #240

Closed
necomarkro opened this issue Mar 1, 2016 · 12 comments
Closed

[GBA] Enable writing RTC state/saving in save file #240

necomarkro opened this issue Mar 1, 2016 · 12 comments
Labels
platform:GBA Game Boy Advance-related issues severity:enhancement Feature requests
Milestone

Comments

@necomarkro
Copy link

In Rockman EXE 4.5 Real Operation there is a menu option for setting the RTC time. On console, when you start a new game it asks you to set the time. You can then go back at anytime to the main menu and change the time at the cost of in-game money and removal from on-going story events. However in mGBA (and every other GBA emulator I have tested) setting the RTC through "New Game" and the mentioned menu option does nothing, regardless of "Gamepack sensors" settings.

How to recreate:

  1. Select top main menu option to create a new game.
  2. Set the time to anything
  3. Continue creating the new game until you get to the in-game menu. Note the time on the top of the screen is not the one you set, rather the emulator's sensor.
  4. Save and reset the game
  5. Select the bottom menu option to set the game time
  6. Say yes to the saving prompt then set the time.
  7. Select the 3rd menu option to load the save game. Note the time on the top of the screen is not the one you set

Due to all the events in the game being based on the RTC, it gets really annoying to mess with your system time (often causing issues with other programs that rely on it). I'd really like to see an emulator support it as it works on console.

(Not sure this will help but when testing the game in VBA-RR, setting the RTC through "New game" and main menu causes an "Unknown RTC command 64" error.)

@endrift
Copy link
Member

endrift commented Mar 2, 2016

Strange, it seems to work on my end. Which version of mGBA are you running, and on what OS?

@necomarkro
Copy link
Author

I'm using mGBA 0.4.0 on Windows 7 64bit

@endrift
Copy link
Member

endrift commented Mar 2, 2016

I won't have a chance to test on that OS until tonight, but in the meantime, make sure you have a clean ROM and not one patched for any reason.

@endrift endrift added the platform:GBA Game Boy Advance-related issues label Jun 24, 2016
@necomarkro
Copy link
Author

I recently tried a nightly of mGBA (0.5-3783-9eb8faf) and I am still having the issue. My ROM is not patched (CRC32: a646601b).

While you can use the emulator options to tweak the RTC time or manually change your windows time, you cannot set the time using the in-game menu option.
This is a big deal for speedrunners as the emulator runs cannot be compared to the console runs and it makes practicing the game is a pain on emulator.

Also, the game time seems to be off from the sensor time by 6 hours when set to "Fixed time" and "Start time at". However, "System time" is not off by 6 hours

@endrift
Copy link
Member

endrift commented Sep 14, 2016

I'm guessing you're in EST? Timezones might be screwing this up.

As for the actual timer issue, I misunderstood your request. mGBA does not save the value stored back into the RTC by the game, which does in fact cause some issues on the GB games that use the RTC. Right now, the best way to work around this is to use the "start time at" setting every time you load the game. This will keep the time incrementing properly, but you get to set what time the game thinks it is when you boot it. I'll see if I can improve this behavior in the future.

@endrift endrift added this to the 0.6.0 milestone Sep 14, 2016
@endrift endrift modified the milestones: 0.6.0, 0.6.1 Apr 22, 2017
@endrift
Copy link
Member

endrift commented Aug 4, 2017

Partially fixed by ffa7e9b, but to save the value you set the RTC to would require changes to the savegame format.

@endrift endrift modified the milestones: mGBA 0.6.1, mGBA 0.6.2 Sep 30, 2017
@endrift endrift modified the milestones: mGBA 0.6.2, mGBA 0.7.0 Apr 14, 2018
@endrift endrift modified the milestones: mGBA 0.7.0, mGBA 0.7.1 Jan 26, 2019
@endrift endrift modified the milestones: mGBA 0.7.1, mGBA 0.7.2 Feb 25, 2019
@endrift endrift modified the milestones: mGBA 0.7.2, mGBA 0.8.0 Mar 4, 2019
@endrift endrift modified the milestones: mGBA 0.8.0, mGBA 0.9.0 Jan 22, 2020
@endrift endrift changed the title Rockman EXE 4.5 Real Operation RTC [GBA] Enable writing RTC state/saving in save file Mar 16, 2021
@endrift endrift added the severity:enhancement Feature requests label Mar 16, 2021
@endrift endrift modified the milestones: mGBA 0.9.0, mGBA 0.10.0 Mar 16, 2021
@endrift
Copy link
Member

endrift commented Mar 16, 2021

Retargeting this bug report for adding RTC writeback (which is not what the Pokemon games use for some reason), since the other stuff seems to have been fixed by now.

portableandroid pushed a commit to portableandroid/mgba that referenced this issue Jan 8, 2022
@profi200
Copy link

profi200 commented Feb 6, 2022

@lesserkuma
A bit later than i wanted but let's talk about the format you described in #2431. Is there a reason you choose this split design with RTC date + time and a timestamp? I assume you calculate the actual correct time and date (difference between RTC and timestamp plus difference between timestamp and current date and time).

I personally think saving the RTC as offset would be easier to work with.

@lesserkuma
Copy link

@profi200
I looked at existing RTC-state implementations (e.g. Game Boy MBC3 and HuC-3) on emulators, and that seems to be the scheme that had been agreed on; raw values as you would read them from the RTC component plus a timestamp that is used for synchronization.
In the case of the GBA GPIO RTC, there’s also the weekday value which can be a bit odd. I observed two different things with it. In Pokémon games, the RTC seems to be never written to (I may be wrong), and all values just count up from their smallest possible value, but that also means it uses the Sunday value for 2000/1/1. Boktai properly initializes the weekday value to Saturday for 2000/1/1. I didn’t check other RTC games yet.

@profi200
Copy link

profi200 commented Feb 6, 2022

I thought the Pokémon games reset the RTC to 2000.1.1 00:00 each time you start a new game? But yeah, these games don't use the day of week counter. I have not pushed it yet but i implemented the weekday stuff (0 = sunday like most RTCs).

https://gist.github.com/profi200/8c617f3ea4366474cb3ffcb54e41393a

@lesserkuma
Copy link

lesserkuma commented Feb 6, 2022

Just re-tested it with a retail Pokémon Ruby cartridge! Just starting a new game keeps the old RTC values, but when pushing SELECT+UP+B on the title screen, deleting everything and then starting a new game, this will reset the RTC back to 2000/1/1 00:00:00 @ Sunday. When synchronizing/forward-adjusting the RTC values in software, one could count the days passed since the timestamp and then do weekday = (weekday + days_passed) % 7 to account for all game-specific oddities.

@profi200
Copy link

profi200 commented Feb 9, 2022

Yeah, that should work. I guess we will go with that format then. Annoying for me since i have to convert back and forth multiple times. I only have BCD and that weird offset in hardware. No unix like timestamps.

As for embedding the RTC data in save files i'm still not sure but it's probably the most compatible and (from an end user perspective) the easiest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:GBA Game Boy Advance-related issues severity:enhancement Feature requests
Projects
None yet
Development

No branches or pull requests

4 participants