Mednafen Members Members   Search Search   Help Help   Register Register   Login Login   Home Home
Home » Mednafen » Development » RTC problem and possible fix
Show: Today's Messages  :: Show Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
RTC problem and possible fix [message #2226] Fri, 02 September 2011 14:57 Go to next message
aiedail92  [PM]
Hi!

First of all, thank you for this great software.

I used to run mednafen 0.8.* with the "little patch" to enable the GBA RTC. I recently decided to try the latest 0.9.18-wip which has the RTC enabled out-of-the-box. It works -- games running under non-patched 0.8.* complained about "battery running dry", while with 0.9.18 they don't -- but it actually doesn't: the clock (Pokémon Emerald) doesn't move.

I tried to look at the sources, and it turned out that the member variable RTC::curtime, which is then used in RTC::Write, never gets updated after the first call to RTC::InitTime (in the constructor).

I came out with a patch that fixes the problem, but I'm not sure if this is the right way:

diff -rup original/src/gba/RTC.cpp patched/src/gba/RTC.cpp
--- original/src/gba/RTC.cpp	2011-09-02 23:43:01.917705222 +0200
+++ patched/src/gba/RTC.cpp	2011-09-02 23:45:38.917699635 +0200
@@ -111,7 +111,9 @@ void RTC::Write(uint32 address, uint16 v
                 struct tm *newtime;
                 time_t long_time;
 
-                long_time = curtime / 16777216;
+                time(&long_time);
+
+                this->curtime = (int64)long_time * 16777216;
                 newtime = localtime( &long_time ); /* Convert to local time. */
                 
                 dataLen = 7;
@@ -130,7 +132,9 @@ void RTC::Write(uint32 address, uint16 v
                 struct tm *newtime;
                 time_t long_time;
 
-		long_time = curtime / 16777216;
+                time(&long_time);
+
+                this->curtime = (int64)long_time * 16777216;
                 newtime = localtime( &long_time ); /* Convert to local time. */
                 
                 dataLen = 3;


By the way, is it possible to have read access to the SVN (or git, or whatever VCS you use) sources?

Many thanks, and sorry for my bad English,

Luca

  • Attachment: fix-rtc.patch
    (Size: 0.97KB, Downloaded 281 time(s))

Re: RTC problem and possible fix [message #2227 is a reply to message #2226 ] Fri, 02 September 2011 15:39 Go to previous messageGo to next message
Administrator  [PM]
Oops.

That's one way to fix it, though doing that will break recorded input log-style movies and netplay, and wasn't the direction I was intending the code to go.

Below is the other way, which allows those features to work properly, but emulated RTC time will slowly desynch from system time.


Add this method to RTC:
void RTC::AddTime(int32 amount)
{
 curtime += amount;
}


(add AddTime to the class definition in the header file too)

and in Emulate() in GBA.cpp, after the while() CPULoop() loop,
add a call to it such that it looks like:

 while(!frameready && (soundTS < 300000))
  CPULoop(espec->surface, 300000);

 if(GBA_RTC)
  GBA_RTC->AddTime(soundTS);

 espec->MasterCycles = soundTS;



There isn't a revision control system as such for Mednafen, as there was never really a great need for it.
Re: RTC problem and possible fix [message #2228 is a reply to message #2227 ] Sat, 03 September 2011 01:57 Go to previous message
aiedail92  [PM]
Ok, thank you for your answer Smile

Luca
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic:Mega Drive / Genesis - x24C01 EEPROM Support
Next Topic:MedGui translation
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ ]

Current Time: Sat May 18 11:53:04 CDT 2024
.:: Contact :: Home ::.

Powered by FUDforum.
Copyright © FUDforum Bulletin Board Software