CPCWiki forum

General Category => Emulators => Topic started by: Devilmarkus on 19:55, 23 September 09

Title: Realtime clock for Emulators?
Post by: Devilmarkus on 19:55, 23 September 09
Hi together,
a mail from TFM gave me an idea.

Wouldn't it be nice to have a realtime-clock in emulators?
As I think, port-range &FEF0 - &FEFF is unused. (&FEFE is reserved for emulator-ID)
So I played a bit with JavaCPC and sent system date to several port numbers:

- &FEF2 - Value for month (1-12)
- &FEF4 - Value for daynumber (1-31)
- &FEF6 - Value for hour (0-24)
- &FEF8 - Value for minute (0-59)
- &FEFA - Value for second (0-59)
- &FEFC - Value for day of the week (1-7)

The result is really impressive: A simple realtime clock, which can also be used in BASIC:
(http://cpcwiki.eu/forum/realtimeclock.gif)

The BASIC program for showing this clock is really simple and in 1kByte possible:
100 MODE 1:LOCATE 1,1:PRINT"0 = 24 hours, 1 = 12 hours"
110 a$=INKEY$:IF a$="" THEN GOTO 110
120 IF a$="1" OR a$="0" THEN GOTO 140
130 GOTO 110
140 IF a$="1" THEN format=1 ELSE format=0
150 MODE 1:LOCATE 1,1:PRINT"JavaCPC realtime clock test"
160 PRINT:PRINT
170 hou=INP(&FEF6):IF hou>12 AND format=1 THEN hou=hou-12
180 minu=INP(&FEF8)
190 seku=INP(&FEFA)
200 day=INP(&FEFC)
210 month=INP(&FEF2)
220 dayno=INP(&FEF4)
230 RESTORE 240:FOR t=1 TO day:READ day$:NEXT
240 DATA Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
250 RESTORE 260:FOR t=0 TO month:READ month$:NEXT
260 DATA January,February,March,April,May,June,July,August,September,October,November,December,January
270 LOCATE 1,23:PRINT hou;":";minu;":";seku:PRINT"Today is ";day$;",";dayno;"th. ";month$;"      ":GOTO 170


Question: Do other emulators feature this, too?
If yes: How? Do they send informations to ports, too?
If no: Maybe cool, if other emulators could feature this, too.

Cheers,
Markus
Title: Re: Realtime clock for Emulators?
Post by: Octoate on 20:14, 23 September 09
AFAIK WinApe already features RTC support. If you emulate that, you should aim on hardware compatibility and emulate existing devices. E.g. it would be better to emulate the Symbiface II RTC instead of creating something by yourself. You can get more information on the Symbiface II RTC in the following CPC Wiki article: http://cpcwiki.eu/index.php/SYMBiFACE_II:Realtime_clock (http://cpcwiki.eu/index.php/SYMBiFACE_II:Realtime_clock)
Title: Re: Realtime clock for Emulators?
Post by: Devilmarkus on 20:49, 23 September 09
Thanks for this tip.

I will try to emulate it.

For my clock I used a simple routine in readPort:
  public int readPort(int port) {
    cal = Calendar.getInstance();
    int result = 0xFF;
    if (port == 0xFEFE) { /* Emulator ID */
      result = 0xA0;
    }
    if (port == 0xFEF2) { /* Month */
      result = cal.get(Calendar.MONTH);
    }
    if (port == 0xFEF4) { /* Day */
      result = cal.get(Calendar.DAY_OF_MONTH);
    }
    if (port == 0xFEF6) { /* Hours */
      result = cal.get(Calendar.HOUR_OF_DAY);
    }
    if (port == 0xFEF8) { /* Minutes */
      result = cal.get(Calendar.MINUTE);
    }
    if (port == 0xFEFA) { /* Seconds */
      result = cal.get(Calendar.SECOND);
    }
    if (port == 0xFEFC) { /* Day */
      result = cal.get(Calendar.DAY_OF_WEEK);
    }
    return result;
  }
Title: Re: Realtime clock for Emulators?
Post by: Gryzor on 05:43, 24 September 09
I think Octoate is right... Since there were a couple of RTC solutions, it'd make lots of sense.

Even so, it's neat indeed, but what's the use? :D It'd be neater if the emu itself could read the user's timezone and adjust the clock automatically, wouldn't it?
Powered by SMFPacks Menu Editor Mod