Page 1 of 3
print correctly BCD CMOS RTC values
Posted: Sat Oct 13, 2018 4:28 pm
by alberinfo
hi,
i'm trying to implement a rtc with cmos(it isn't updated in github)i can get the values, but when i try to print it i only get something buggy.when i was reading some other post, i understood that this is cause it is in BCD and not as int values, so i have to convert it, but the only two abiavle ways that can compile with my code, doesn't work, they just display the same.how can i convert a BCD to a int value?
Re: print correctly BCD CMOS RTC values
Posted: Sat Oct 13, 2018 4:35 pm
by alexfru
Re: print correctly BCD CMOS RTC values
Posted: Sat Oct 13, 2018 4:37 pm
by alberinfo
thanks, but this actually didn't work for me.
Re: print correctly BCD CMOS RTC values
Posted: Sat Oct 13, 2018 5:38 pm
by alexfru
alberinfo wrote:thanks, but this actually didn't work for me.
How so? Elaborate please.
Re: print correctly BCD CMOS RTC values
Posted: Sat Oct 13, 2018 5:49 pm
by alberinfo
i didn't see anything to 'convert' BCD to INT, also the only two ways that i see that are:
and:
Code: Select all
((hour & 0xF0) >> 4) * 10 + (hour & 0x0F)
makes the same result as the image above
Re: print correctly BCD CMOS RTC values
Posted: Sat Oct 13, 2018 6:03 pm
by alexfru
Then, perhaps, the problem is not in conversion but in reading the values from the chip or your prgram being somehow broken (not read from disk correctly, not having correct values in e.g. segment registers).
Re: print correctly BCD CMOS RTC values
Posted: Sun Oct 14, 2018 4:01 am
by thomtl
CMOS Please look at the wiki before posting.
Re: print correctly BCD CMOS RTC values
Posted: Sun Oct 14, 2018 7:22 am
by sortie
You can look at how I've implemented it:
https://gitlab.com/sortix/sortix/blob/m ... y/cmos.cpp
That should be a readable & good example. It also avoids race conditions when the value is being updated.
Re: print correctly BCD CMOS RTC values
Posted: Sun Oct 14, 2018 6:07 pm
by alberinfo
thanks, but either the
CMOS method or the method provided by sortie didnt work, still displaying the 'S' in the screen
Re: print correctly BCD CMOS RTC values
Posted: Sun Oct 14, 2018 6:11 pm
by alexfru
alberinfo wrote:thanks, but either the
CMOS method or the method provided by sortie didnt work, still displaying the 'S' in the screen
Can you test separately:
- single character printing
- string printing
- conversion of integer to hex digits and hex chars ('0'-'9','A'-'F')
- conversion of integer to decimal digits and chars ('0'-'9')
- conversion from BCD to integer
Re: print correctly BCD CMOS RTC values
Posted: Sun Oct 14, 2018 11:49 pm
by thomtl
Could you post your source, since your github is severely outdated.
Re: print correctly BCD CMOS RTC values
Posted: Mon Oct 15, 2018 8:15 am
by alberinfo
i've updated it, but anyway, i don't know what or why fails
Re: print correctly BCD CMOS RTC values
Posted: Mon Oct 15, 2018 8:21 am
by thomtl
You've swapped around your outb functions, the correct syntax for you outb function is
and you're using
also you should really reorganise your project a good example for this is
Meaty_Skeleton.
And because you have copied and pasted so much code by @pvc there are 2 outb functions outb and outportb, OSDev is more than just copying code from others it's about writing code yourself and creating your own OS.
Re: print correctly BCD CMOS RTC values
Posted: Mon Oct 15, 2018 8:23 am
by alberinfo
i see in the outportb function that is first the port and then the data as you say.
Re: print correctly BCD CMOS RTC values
Posted: Mon Oct 15, 2018 8:23 am
by thomtl
Please read my edit