no-software internal RTC

Current solutions and designs.
tzok
Posts: 147
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Tue Aug 28, 2018 3:45 pm

Petari wrote:
Tue Aug 28, 2018 3:15 pm
Obviously you did not read what I wrote, and you don't care for. How can you see what is added and what not by looking only signals and not code?
I do care, but not understand... I see raw data being sent to the IKBD, so if TOS would add anything, I should see it. When I set 1999 I see 0x99 being sent, while according to you 0xE9 (0x99 + 0x50) should be sent - but it is not. TOS can't change anything outside ST board, so why I see 0x99 leaving an ST board and going to IKBD? What's more - when I set 2018 in OMIKRON.Basic's DATE$ command I see 0xB8 being sent to IKBD. IKBD has its own firmware, so if TOS would add anything I would see this by observing transmission between ST and IKBD. I'm using a hardware protocol analyzer on a real ST. I'm not using any kind of debugger/emulator setup. What I misunderstood?

Petari
Trusted Guru
Trusted Guru
Posts: 550
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Tue Aug 28, 2018 3:55 pm

tzok wrote:
Tue Aug 28, 2018 3:45 pm
...
I do care, but not understand... I see raw data being sent to the IKBD, so if TOS would add anything, I should see it. When I set 1999 I see 0x99 being sent, while according to you 0x49 (0x99 - 0x50) should be sent ....
" TOS code (I looked 1.04) adds $80 (writing in hex because it is how CPU sees it) to packed BCD value of year before writing it to IKBD," - As said, you did not read it ... Btw. same is in 1.62 . One day I will check 2.06 .
According to me, for year 1999 $19 (packed BCD) should be sent. And $99 (packed BCD) for year 2079 - if there will be working Atari then :D
Writing there real year value - actually part of it has not much sense.
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

tzok
Posts: 147
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Tue Aug 28, 2018 6:25 pm

Petari wrote:
Tue Aug 28, 2018 3:55 pm
" TOS code (I looked 1.04) adds $80 (writing in hex because it is how CPU sees it) to packed BCD value of year before writing it to IKBD," - As said, you did not read it ... Btw. same is in 1.62 . One day I will check 2.06 .
According to me, for year 1999 $19 (packed BCD) should be sent. And $99 (packed BCD) for year 2079 - if there will be working Atari then :D
Writing there real year value - actually part of it has not much sense.
Ok, you've read this in some book, I've checked it and what you've read is apparently wrong. I physically checked what is being sent to IKBD and for year 1999 a value of 0x99 (hex) is sent. DOn't blame me. I've checked it on 2 different TOS versions. I was physically (well, via the protocol analyzer) listening on the IKBD UART.

Petari
Trusted Guru
Trusted Guru
Posts: 550
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Tue Aug 28, 2018 6:53 pm

Yes, $99 is what is sent for 1999. What I said is that it is bad solution, and it is the reason why it works not with year 2000 and above.
It's not that I just read it in some book, I traced it with debugger.
Then: "According to me, for year 1999 $19 (packed BCD) should be sent." - does it looks like 'what is sent' or 'what should be sent' .
I think that this was really enough of this. You have problems with English, or just not enough patient to read carefully what is written.
Don't blame book if you can not read it :lol:
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

tzok
Posts: 147
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Tue Aug 28, 2018 7:15 pm

I'm not a native english speaker... but still "this is what should be sent" (in context of analyzing source code or documentation) sounds for me like "what I should see on the logic analyzer". Nevertheless - why you don't like my solution so much? TOS 1.62 (via the CONTROL.ACC) and TOS 2.06 (directly) seem to interpret 0xB8 just fine, as a 2018. So where is the problem?

Obviously the IKBD RTC is not 2k compliant, but TOS seems to be. So I guess You meant that the TOS should have been programmed to subtract/add $80 in order to store only a difference from 1980 in IKBD, but it is not doing so. I'm not sure if in such case its calendar routines would work correctly (I mean in which year February has 28 or 29 days). They need to be changed in IKBD firmware as well.

Petari
Trusted Guru
Trusted Guru
Posts: 550
Joined: Tue Nov 28, 2017 1:32 pm

Re: no-software internal RTC

Post by Petari » Tue Aug 28, 2018 8:13 pm

My last post here:
You talk generally about TOS, while your solution works only with 2.06. What I don't like is that you present this as something 'absolute', "no-software", and it works only with 2.06 . Well, my Mega STE with 2.06 does not need it - it has Ricoh RTC chip :D

Last time: TOS calculates date starting from year 1980 - it is stored as 0 in 7 bits provided for year in word for date (stays for all versions). TOS 1.xx adds $80 to it when writes to IKBD, and subs same after reading. Not 'should' , it does it. And that's what limits year span to only 20 years - 1980-1999 - in IKBD chip. Without that adding it would be up to 2079 (I write it for about 79-th time here :D ) .
I don't know is IKBD chip deals with correct lap year February day count - may be that it was the reason for that adding, but that's irrelevant now.
Changing IKBD firmware - please do it .
There is 2 kind of people: one thinking about moving to Mars after here becomes too bad, the others thinking about how to keep this planet habitable.

mikro
Posts: 164
Joined: Mon Aug 28, 2017 11:22 pm

Re: no-software internal RTC

Post by mikro » Tue Aug 28, 2018 9:21 pm

Actually Petari is right - this isn't such a great solution as it seemed to be. You have basically built a hardware mod which can be done in software and as a bonus, you need yet another software (CONTROL.ACC) to make it work on TOS 1.02 - 1.62.

This way is just easier to have one software patch which works everywhere.

tzok
Posts: 147
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Tue Aug 28, 2018 10:17 pm

Petari wrote:
Tue Aug 28, 2018 8:13 pm
Last time: TOS calculates date starting from year 1980 - it is stored as 0 in 7 bits provided for year in word for date (stays for all versions). TOS 1.xx adds $80 to it when writes to IKBD, and subs same after reading. Not 'should' , it does it. And that's what limits year span to only 20 years - 1980-1999 - in IKBD chip. Without that adding it would be up to 2079 (I write it for about 79-th time here :D ) .
I don't know is IKBD chip deals with correct lap year February day count - may be that it was the reason for that adding, but that's irrelevant now.
Changing IKBD firmware - please do it .
Now I understand the problem, this time it is clear to me. The IKBD stores two last digits (decimal) of year, while TOS internally stores only a number of years since 1980 on 7 bits. So TOS should accept any year between 1980 (0) and 2107 (127). Its dec2bcd and bcd2dec are "dummy", with no asserts, and they will work beyond 0x99, still returning a valid value for internal TOS year format calculation.
Petari wrote:
Tue Aug 28, 2018 8:13 pm
Changing IKBD firmware - please do it .
Instead of patching the IKBD firmware I propose to add some custom hardware module between IKBD and ST to intercept all date/time queries (literally 0x1C an 0x1B) and process it in this module. As my proposition is Arduino based so it should be much simpler as a DIY project than patching a TOS. Also, I want to keep my ST as close to stock machine as I can be to keep it usable. My mod is completely non-invasive, as it just requires to plug a device between keyboard and motherboard - no cutting wires/traces, no soldering on Atari HW.
mikro wrote:
Tue Aug 28, 2018 9:21 pm
You have basically built a hardware mod which can be done in software and as a bonus, you need yet another software (CONTROL.ACC) to make it work on TOS 1.02 - 1.62.

This way is just easier to have one software patch which works everywhere.
The software patch still needs some additional hardware (RTC module) and/or some non-stock/custom software/drivers. My hardware just doesn't need a patched TOS and may be used with a standard software bundled with the computer. Or other way around - other modules need additional software and/or patching a TOS, my - doesn't.

tzok
Posts: 147
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Wed Aug 29, 2018 11:12 am

Here is the working code (without option to set RTC):

Code: Select all

/******************************************************************
 Created with PROGRAMINO IDE for Arduino
 Project     : Atari ST IKBD clock injector with DS3231 RTC
 Libraries   : SoftwareSerial, Wire
 Author      : tzok
 Description : ARD_RX0 from KB_5, ARD_TX1 to ST_5, ARD_D10 from/to KB/ST_6
******************************************************************/

#include <SoftwareSerial.h>
#include <Wire.h>

#define DS3231_ADDRESS (0x68)
#define DS3231_REG_TIME (0x00)

SoftwareSerial Control(10, 11);

int inject = -1;
byte date[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC};
//                ss,   mm,   hh,   DD,   MM,   YY
byte ds3231[7];

void setup()
{
    Serial.begin(7812);
    Control.begin(7812);
    Control.listen();
    Wire.begin();
}

void loop()
{
  if (Control.available())
  {
    if (Control.read() == 0x1C)
    {
      Wire.beginTransmission(DS3231_ADDRESS);
      Wire.write(DS3231_REG_TIME);
      Wire.endTransmission();
      Wire.requestFrom(DS3231_ADDRESS, 7);
      while(!Wire.available()) {};
      for (int i = 6; i >= 0; i--)
      {
        ds3231[i] = Wire.read();
      }
      date[5] = ds3231[0] + 0xA0; // YY
      date[4] = ds3231[1] & 0x1F; // MM
      date[3] = ds3231[2]; // DD
      date[2] = ds3231[4] & 0x1F; // hh
      date[1] = ds3231[5]; // mm
      date[0] = ds3231[6]; // ss
      inject = 6;
    }
  }
  if (Serial.available())
  {
    if (inject == -1)
      Serial.write(Serial.read());
    else
    {
      Serial.read();
      Serial.write(date[inject--]);
    }
  }
}

tzok
Posts: 147
Joined: Sat Dec 30, 2017 2:27 pm

Re: no-software internal RTC

Post by tzok » Wed Aug 29, 2018 4:02 pm

...and fully featured version, with ability to set the RTC using CONTROL.ACC:

Code: Select all

/******************************************************************
 Created with PROGRAMINO IDE for Arduino - 06.08.2018 15:23:03
 Project     : Atari ST IKBD clock injector with DS3231 RTC
 Libraries   : SoftwareSerial, Wire
 Author      : tzok
 Description : ARD_RX0 from KB_5, ARD_TX1 to ST_5, ARD_D10 from/to KB/ST_6
******************************************************************/

#include <SoftwareSerial.h>
#include <Wire.h>

#define DS3231_ADDRESS (0x68)
#define DS3231_REG_TIME (0x00)

SoftwareSerial Control(10, 11);

byte cmd;
int inject = -1;
byte date[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC};
//                ss,   mm,   hh,   DD,   MM,   YY
byte ds3231[7];

void setup()
{
    Serial.begin(7812);
    Control.begin(7812);
    Control.listen();
    Wire.begin();
}

void loop()
{
  if (Control.available())
  {
    cmd = Control.read();
    if (cmd == 0x1C)
    {
      Wire.beginTransmission(DS3231_ADDRESS);
      Wire.write(DS3231_REG_TIME);
      Wire.endTransmission();
      Wire.requestFrom(DS3231_ADDRESS, 7);
      while(!Wire.available()) {};
      for (int i = 6; i >= 0; i--)
      {
        ds3231[i] = Wire.read();
      }
      date[5] = ds3231[0] + 0xA0; // YY
      date[4] = ds3231[1] & 0x1F; // MM
      date[3] = ds3231[2]; // DD
      date[2] = ds3231[4] & 0x1F; // hh
      date[1] = ds3231[5]; // mm
      date[0] = ds3231[6]; // ss
      inject = 6;
    }
    else if (cmd == 0x1B)
    {
      for (int i = 5; i >=0; i--)
      {
        while(!Control.available()) {};
        date[i] = Control.read();
      }
      ds3231[0] = date[5] - 0xA0; // YY
      ds3231[1] = date[4]; // MM
      ds3231[2] = date[3]; // DD
      ds3231[4] = date[2]; // hh
      ds3231[5] = date[1]; // mm
      ds3231[6] = date[0]; // ss
      Wire.beginTransmission(DS3231_ADDRESS);
      Wire.write(DS3231_REG_TIME);
      for (int i = 6; i >= 0; i--)
      {
        Wire.write(ds3231[i]);
      }
      Wire.write(DS3231_REG_TIME);
      Wire.endTransmission();
    }
  }
  if (Serial.available())
  {
    if (inject == -1)
      Serial.write(Serial.read());
    else
    {
      Serial.read();
      Serial.write(date[inject--]);
    }
  }
}
...actually CONTROL.ACC sends to IKBD value 0xB8 for year 18.

Post Reply

Return to “RTC (Real time clock)”