MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Flat Mode Flat  

byuu
MAME Fan
Reged: 03/17/06
Posts: 41
Send PM
Re: Aristocrat Mark 4 - need help with DS1302
05/21/09 01:18 AM



Quote:


I could always get the time/date from the PC system and return that from my read handler but I guess that is almost cheating ?




If you're asking for how to emulate an RTC in general, there's caveats no matter what you do.

1. Use gettimeofday(), etc (eg use PC time):
Pros:
- no external files to keep track of time
- easy for user to adjust the time shown in-game

Cons:
- cannot simulate running emulation too fast or slow
- in-game clock setting / adjustment tools do nothing
- games that set the clock to test if its working fail
- libc functions break when you try and go before or after the platform epoch (eg pre-1970 and such)

2. Keep a time_t stamp as a diff. Each time the RTC is accessed, get a new time_t, determine the difference, update the emulated time, and sync the time_t values.
Pros:
- can set time in-game, test and adjust functions work

Cons:
- have to save the last time_t stamp to a file
- still can't simulate running fast or slow, or emulated time will desync with real time

3. Do not store a diff, increment counter along with running emulation.
Pros:
- again, no file on disk
- can properly simulate emulated time even during fast forward and rewind
- only option that is fully safe for save states

Cons:
- time does not pass with emulator closed. Trying to use a time_t diff only when the emulator is closed will only help a little, as time will still desync from PC time very easily.

----------

Bottom line is time adjust functions and RTC chips do not mix well together, and there's no bullet-proof solution to that.

So, it's really up to you. I prefer option 2, so long as users don't fast forward / rewind during hardware tests, and avoid save states, they get very accurate time passage that stays in sync with the PC time properly.

Option 3 is required if you want to make emulation completely invisible to the emulated hardware no matter what, but absolutely sucks to end users who are trying to keep the time in sync with their PCs.

Option 1 is just lazy :P
Only use that on games that do absolutely nothing with the RTC but show the time.







Entire thread
Subject Posted by Posted on
* Aristocrat Mark 4 - need help with DS1302 palindrome 05/18/09 03:10 PM
. * Re: Aristocrat Mark 4 - need help with DS1302 Sune  06/22/09 08:36 AM
. * Re: Aristocrat Mark 4 - need help with DS1302 byuu  05/21/09 01:18 AM
. * Re: Aristocrat Mark 4 - need help with DS1287 palindrome  05/28/09 11:48 AM
. * Re: Aristocrat Mark 4 - need help with DS1302 R. Belmont  05/19/09 01:25 AM
. * Re: Aristocrat Mark 4 - need help with DS1302 palindrome  05/19/09 03:58 PM
. * Re: Aristocrat Mark 4 - need help with DS1302 R. Belmont  05/20/09 08:13 PM
. * Re: Aristocrat Mark 4 - need help with DS1287 palindrome  05/28/09 11:51 AM

Extra information Permissions
Moderator:  Pi 
0 registered and 16 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 4818