print correctly BCD CMOS RTC values

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

print correctly BCD CMOS RTC values

Post 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?
Attachments
cmos bug.jpg
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: print correctly BCD CMOS RTC values

Post by alberinfo »

thanks, but this actually didn't work for me.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: print correctly BCD CMOS RTC values

Post by alexfru »

alberinfo wrote:thanks, but this actually didn't work for me.
How so? Elaborate please.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: print correctly BCD CMOS RTC values

Post by alberinfo »

i didn't see anything to 'convert' BCD to INT, also the only two ways that i see that are:

Code: Select all

(((hour & 0xF0) >> 4) < 10)
and:

Code: Select all

((hour & 0xF0) >> 4) * 10 + (hour & 0x0F)
makes the same result as the image above
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: print correctly BCD CMOS RTC values

Post 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).
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: print correctly BCD CMOS RTC values

Post by thomtl »

CMOS Please look at the wiki before posting.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: print correctly BCD CMOS RTC values

Post 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.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: print correctly BCD CMOS RTC values

Post by alberinfo »

thanks, but either the CMOS method or the method provided by sortie didnt work, still displaying the 'S' in the screen
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: print correctly BCD CMOS RTC values

Post 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
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: print correctly BCD CMOS RTC values

Post by thomtl »

Could you post your source, since your github is severely outdated.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: print correctly BCD CMOS RTC values

Post by alberinfo »

i've updated it, but anyway, i don't know what or why fails
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: print correctly BCD CMOS RTC values

Post by thomtl »

You've swapped around your outb functions, the correct syntax for you outb function is

Code: Select all

void outb(word port, word value);
and you're using

Code: Select all

void outb(word value, word port);
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.
Last edited by thomtl on Mon Oct 15, 2018 8:23 am, edited 1 time in total.
alberinfo
Member
Member
Posts: 122
Joined: Wed Aug 29, 2018 4:42 pm

Re: print correctly BCD CMOS RTC values

Post by alberinfo »

i see in the outportb function that is first the port and then the data as you say.
User avatar
thomtl
Member
Member
Posts: 66
Joined: Mon Sep 03, 2018 2:25 am

Re: print correctly BCD CMOS RTC values

Post by thomtl »

Please read my edit
Post Reply