Author Topic: GBA X5 RTC Display Bug  (Read 433 times)

0 Members and 1 Guest are viewing this topic.

Offline voltar

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
GBA X5 RTC Display Bug
« on: February 07, 2020, 02:09 PM »
There is a display issue with the RTC clock in the diagnostic menu. It will display year 2021 when the RTC clock is set to year 2020. This is with the latest OS v1.12

This can be reproduced by using Boktai to set the clock. If the clock is set to 02/07/2019 the diagnostic will show 02/07/2019, if it is set to 02/07/2020 the diagnostic will show 02/07/2021 and if it is set to 02/07/2021 the diagnostic will show 02/07/2021. The time will continue to display correctly in Boktai after restarting.

I confirmed this is only a display issue using Pokemon Emerald. I set the time to 02/07/2020 with the diagnostic showing 02/07/2021 then planted berries. I then copied the save to an EZ Flash Omega, the Omega RTC was also set to 02/07/2020. The berries were still not grown. I change the Omega RTC to 02/08/2020 and the berries were then grown. I also did this in the other direction to confirm it has the correct time.

It would be nice if an option was added to set the Everdrive GBA RTC clock similar to what the Everdrive GB X7 has. This is causing a lot of confusion as there is a lot of information online that the Omega has a better RTC system or that the Everdrive GBA X5 RTC breaks with multiple RTC roms. I've tested a lot with both the Omega and Everdrive and it is the same RTC system. The only difference is the Omega will block games from resetting the RTC clock so it stays consistent when creating new Pokemon saves. The same can be accomplished on the Everdrive by keeping the RTC clock set to a time zone using Boktai. When creating new Pokemon saves correct the time again using Boktai. This will keep the RTC consistent on all the Pokemon saves the same as the Omega does. Also the Omega has a major issue with the RTC clock running really slow when powered off. I've never had this issue with any Everdrives and the save system is more reliable.

Adding the option to set the RTC clock on the Everdrive and blocking RTC updates from roms as the Omega does would fix the RTC issues on the Everdrive. I think this is a better system then the dual RTC/offset on the GB X7 as the saves will be compatible with any other flashcarts or emulators. The GB X7 saves rely on the offset file to maintain the correct time.

Offline KRIKzz

  • Administrator
  • Hero Member
  • *****
  • Posts: 3260
  • Karma: +489/-2
    • View Profile
Re: GBA X5 RTC Display Bug
« Reply #1 on: February 07, 2020, 03:01 PM »
I thought when you set time in pokemon games they keeps time offset in memory and reset rtc to 0, instead of setting actual time in rtc. In other words if you refuse rtc reset then pokemon games wasn't able to set time. isn't? Are you sure that omega just lock time setup for games?

Offline voltar

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: GBA X5 RTC Display Bug
« Reply #2 on: February 08, 2020, 03:07 AM »
Actually I'm not completely sure how the RTC works. I checked again with a new Pokemon Emerald save and some kind of offset is being store. But the offset is still working on the Everdrive GBA. I set the clock in Emerald to a different time then the Omega RTC, it keeps this time in Pokemon and the Omega RTC doesn't change. If I change the Omega RTC the Emerald time will change relative and maintain the offset. I can then copy the Emerald save to the Everdrive and both will show the same time with an offset.

The strange thing is if I create the save on the Everdrive GBA when I first set the clock to a different time then UTC in Pokemon Emerald it will reset the Everdrive RTC, the Omega RTC wont reset when this is done. But then I can correct the Everdrive RTC to UTC using Boktai and copy the Emerald save to the Omega and they will both end up with the same offset time.

When starting Boktai for the first time it will initially show the time from the Omega RTC during the setup. If it is changed in Boktai it will temporarily show the changed time in the Boktai settings. After about a minute it reverts back to the Omega RTC time ignoring any changes made in Boktai. This happens without the system restarting.

Maybe this is specific to only this ROM and I don't have a good understanding of the GBA RTC system. But I don't think you should be resetting the RTC when the clock changes in Pokemon. I believe what is happening is when the Pokemon cartridges were manufactured as soon as the battery was installed the RTC clock would start. By the time the cartridge was sold and first used some time would have passed on the cartridge RTC. When the cartridge is first used and the clock was set in game I think the Pokemon developers are storing an offset in the save that is relative to the RTC clock in the cartridge. I think this would make more sense from the perspective of the developers as modifying the RTC clock on the cartridge would have required developing a way for the game to communicate to the RTC. It would be easier to just take what ever time is on the RTC and store an offset in the save to keep it relative to that RTC time.

Perhaps the RTC reset in Pokemon is an unnecessary step to prevent an int overflow. Maybe the Pokemon developers used the steps: reset RTC -> ask user for time -> read RTC time -> store offset of users time in save relative to RTC. If this is the case you can ignore that RTC reset and the game will just store an offset of the time it read from RTC which would be the current time instead of a 0 time. I think this is what Omega is doing but it may be dangerous because if the Pokemon developers are taking the RTC time + offset and they expect the RTC to start at year 2000 with a value of 0 there is going to be an overflow if the RTC time is 2020. In fact I suspect what is happening with the Omega is if the RTC on the Omega is set to the current year 2020 when Pokemon is played that calculation is likely overflowing several times. This overflow would only be noticed in the game if by chance an overflowed occurred after the game save was started in which case the time will fall back significantly.

This would explain what I'm seeing happen when moving the saves between the flashcarts. The Boktai developers seem to instead modify the RTC without any offsets but the Omega will ignore these modifications and the RTC will quickly revert back to the Omega RTC time.

I think the only safe way to handle the RTC is to not set the RTC on the flashcart to the current time but instead keep it at a low value around year 2000 as it would be when the games were developed. Given that it is 20 years past what the developers would have expected int overflows will likely occur in games doing calculations with an 2020 RTC time. It's my understanding Pokemon counts days separately so perhaps the RTC calculation isn't ever being interpreted as seconds from 01/01/2000 so maybe overflows are wont happen even with an RTC set to 2020.

But I believe you should be ignoring RTC resets at least from Pokemon as I think the game will just read the current RTC time and store an offset in the save, this will allow multiple Pokemon saves as the Omega does. For users to transfer saves from the Omega to the Everdrive they will just need to match the RTC on both flashcarts.

I don't think Boktai can be played along with Pokemon on either the Omega or Everdrive GBA without the risk of int overflows. The documentation should warn users about this. The Omega developers should be instructing users to set a low time on the RTC instead of the current time to avoid any possible overflows. Ignoring Pokemon RTC resets and adding an option to set the RTC to the Everdrive GBA would solve the RTC issues and allow saves to be copied from the Omega. But if you add this option you should warn users to select a time close to 01/01/2000 instead of the current time.

Offline nuu

  • Hero Member
  • *****
  • Posts: 1250
  • Karma: +58/-2
    • View Profile
Re: GBA X5 RTC Display Bug
« Reply #3 on: February 10, 2020, 06:15 PM »
The strange thing is if I create the save on the Everdrive GBA when I first set the clock to a different time then UTC in Pokemon Emerald it will reset the Everdrive RTC, the Omega RTC wont reset when this is done. But then I can correct the Everdrive RTC to UTC using Boktai and copy the Emerald save to the Omega and they will both end up with the same offset time.
I don't see what's strange, this is expected behaviour. Pokemon resets the RTC at the start of a new game. Omega has isolated RTC which means Pokemon can't touch it. It would only reset a virtual RTC created by the Omega for every played game that needs an RTC.

When starting Boktai for the first time it will initially show the time from the Omega RTC during the setup. If it is changed in Boktai it will temporarily show the changed time in the Boktai settings. After about a minute it reverts back to the Omega RTC time ignoring any changes made in Boktai. This happens without the system restarting.
This sounds like the isolated RTC doesn't work as it should on the Omega.

when the Pokemon cartridges were manufactured as soon as the battery was installed the RTC clock would start. By the time the cartridge was sold and first used some time would have passed on the cartridge RTC. When the cartridge is first used and the clock was set in game I think the Pokemon developers are storing an offset in the save that is relative to the RTC clock in the cartridge.
I think it's confirmed that Pokemon resets the RTC at a new game, if it didn't other games wouldn't be affected by it which they are. Pokemon does indeed store time as an offset though and lets the RTC run from the reset date 2000-01-01, 00:00 without ever touching it again. In other words, manufacturing date has no effect on anything.

I think this would make more sense from the perspective of the developers as modifying the RTC clock on the cartridge would have required developing a way for the game to communicate to the RTC. It would be easier to just take what ever time is on the RTC and store an offset in the save to keep it relative to that RTC time.
The offset makes sense because they don't need the month and week calendars and instead just counts days and time of day, not because they don't need to communicate with the RTC, which they do since they still needs to read and reset it. And as a matter of fact it is fully possible to write to the RTC in a Pokemon cartridge as well as evident by Nintendo's berry glitch patch program and certain homebrew using a cartridge swap: https://github.com/megaboyexe/GBA_RTCRead

if the Pokemon developers are taking the RTC time + offset and they expect the RTC to start at year 2000 with a value of 0 there is going to be an overflow if the RTC time is 2020. In fact I suspect what is happening with the Omega is if the RTC on the Omega is set to the current year 2020 when Pokemon is played that calculation is likely overflowing several times. This overflow would only be noticed in the game if by chance an overflowed occurred after the game save was started in which case the time will fall back significantly.
Yes I guess it's possible that the Pokemon games are not designed to run for 20 years without overflowing, even though the RTC chip itself usually can count a 100 years. Other RTC games may also have bugs eventually.

I think the only safe way to handle the RTC is to not set the RTC on the flashcart to the current time but instead keep it at a low value around year 2000 as it would be when the games were developed. Given that it is 20 years past what the developers would have expected int overflows will likely occur in games doing calculations with an 2020 RTC time. It's my understanding Pokemon counts days separately so perhaps the RTC calculation isn't ever being interpreted as seconds from 01/01/2000 so maybe overflows are wont happen even with an RTC set to 2020.
No if you do that the berry glitch will happen. You should set it to at least 2002-01-02. Also if the berry glitch still haven't happened and you connect to certain Gamecube Pokemon games or e-Reader cards the berry glitch will be "patched" by Nintendo by forwarding the RTC to 2002-01-02.
https://krikzz.com/forum/index.php?topic=9564.msg72490#msg72490

But I believe you should be ignoring RTC resets at least from Pokemon as I think the game will just read the current RTC time and store an offset in the save, this will allow multiple Pokemon saves as the Omega does.
Multiple Pokemon save files is fully possible already. The problem is that if you change the RTC in another game, the hours and minutes in Pokemon will be off by the amount of the offset value. The trick to get around it is to make the offset as close to zero as possible, by setting the wall clock at the start of a new game to a few minutes after midnight (depending on how long the intro took). Then you should set the RTC to 2002-01-02 or later in Boktai or other game (alternatively use Nintendo's berry patcher). You need to do all of this every time you start a new Pokemon game or any other game that works the same way (if there are any) since the RTC is reset every time you do.

There should be no problem in playing Boktai or any other RTC game, and by keeping the Pokemon offset close to 0, the time will be consistent in all games.