Author Topic: Realtime clock for Emulators?  (Read 1293 times)

0 Members and 1 Guest are viewing this topic.

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1014
  • Likes Given: 926
Realtime clock for Emulators?
« on: 21: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:


The BASIC program for showing this clock is really simple and in 1kByte possible:
Code: [Select]
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
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Octoate

  • CPC6128
  • ****
  • Posts: 290
  • Country: de
    • Octoate.de
  • Liked: 62
  • Likes Given: 326
Re: Realtime clock for Emulators?
« Reply #1 on: 22: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
--

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1014
  • Likes Given: 926
Re: Realtime clock for Emulators?
« Reply #2 on: 22:49, 23 September 09 »
Thanks for this tip.

I will try to emulate it.

For my clock I used a simple routine in readPort:
Code: [Select]
  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;
  }
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 15.461
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3088
  • Likes Given: 5679
Re: Realtime clock for Emulators?
« Reply #3 on: 07: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?