Setting day of week in the RTC can both disable the battery and set the wrong day

This is the starting place for reporting bugs to the team. We will pass bug reports on to the developers after validating the reports.

You can report bugs in hardware, operating system (KERNAL or BASIC ROMs), the emulator, or the Demo library. For bugs specific to downloaded programs, use the download forum.
Post Reply
User avatar
Daedalus
Posts: 229
Joined: Fri Nov 11, 2022 3:03 am

Setting day of week in the RTC can both disable the battery and set the wrong day

Post by Daedalus »

The KERNAL call clock_set_date_time (Which in is the file rtc.s and called rtc_set_date_time) has a bug in the section that sets the day of week. After it sets the battery enable bit with ora $08, it calls i2c_write_byte_as_bcd. In doing so, depending on which day of week you were trying to set, it can set the wrong day of week, and if the bin_to_bcd conversion (In the same file.) resets the battery enable bit in the BCD conversion, it will disable the battery.

Changing the i2c_write_byte_as_bcd call to i2c_write_byte fixes it. It was never needed to do the BCD conversion as the legal data is never over 7, attempting to do the bcd conversion IF the battery enable bit PLUS the day of week results in a BCD value over 9 it will create 2 BCD digits, with the low order one wrong and the battery enable bit not set.
TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Re: Setting day of week in the RTC can both disable the battery and set the wrong day

Post by TomXP411 »

Thank you. I've reported this on the ROM Repo. You can track it here:

https://github.com/X16Community/x16-rom/issues/249
User avatar
Daedalus
Posts: 229
Joined: Fri Nov 11, 2022 3:03 am

Re: Setting day of week in the RTC can both disable the battery and set the wrong day

Post by Daedalus »

I should mention this as well, it's not a bug, but a documentation error.

The docs say the range of the dayofweek value stored in the RTC is 0 to 6, but it's not, it's 1 to 7. The way the RTC works is at midnight it rolls some of it's internal values over, and if the dayofweek is 7 at that time, it's rolled over to 1.

The end user is free to decide what that number means... the "week" can start on Sunday as 1, or Monday... or whatever.
TomXP411
Posts: 1785
Joined: Tue May 19, 2020 8:49 pm

Re: Setting day of week in the RTC can both disable the battery and set the wrong day

Post by TomXP411 »

Come to think of it, I remember an issue with that somewhere else, too.

Do you know which file this is documented in? I can make that change.
User avatar
Daedalus
Posts: 229
Joined: Fri Nov 11, 2022 3:03 am

Re: Setting day of week in the RTC can both disable the battery and set the wrong day

Post by Daedalus »

It's in the KERNAL section, under "Clock" It's detailing the fields for the "clock_set_data_time" call. It's the last line in the block. The other data look correct, things like day and month properly start at 1, but day of week starts at 0.
Post Reply