OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 4:29 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: kPrint [edit]and the future[/edit]
PostPosted: Tue Mar 15, 2005 10:43 am 
Hi everybody;

I've just come back off my small break from OSdev and I've developed my ideas more. Ideas are no match for this ;,(.

In febuary, I wrote a kPrint function that, like a lot of things, didn't work. In fact, under bochs, the cursor ran around for 30 seconds wildly and without purpose erasing everything when the function was used.

I'll have the code in about a few hours to post.

[edit]
Once I'm done this, I'm gonna move on to Interupt handeling, besides OSfaq (which I visit frequently), where is some good resources and theory for people who understand what they do, but not how to go about catching and using them. Thanks ahead!!
[/edit]

Cheers, DH

PS. Also, I can't seem to figure out how to print numbers. What I mean is, it always comes out as a symbole! Thanks ahead. (Could be credited to my kPutChar which handels all printing in the end ::))


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Tue Mar 15, 2005 12:24 pm 
Dragon_Hilord wrote:
PS. Also, I can't seem to figure out how to print numbers. What I mean is, it always comes out as a symbole! Thanks ahead. (Could be credited to my kPutChar which handels all printing in the end ::))


Sounds like you have problems with your hex->ascii conversion routine.


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Tue Mar 15, 2005 12:30 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
printing a number means computing what digits to display to produce the representation of that number.

since 1234 = 4 + 10*3 + 100*2 + 1000*1, if you recursively divide "1234" by ten and use the result of the division, you get all the digits:

Code:
1234 = 123*10 + 4
123 = 12*10 + 3
12 = 1*10 + 2
1 = 1


digits to be displayed are '1','2','3','4' ...

if you know the numerical value of number%10, you simply have to add this to the character '0' to have the correct character (e.g. '0'+4 == '4')

knowing this, any kprint code that can display numbers will become easy to understand ...

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Tue Mar 15, 2005 4:59 pm 
Curufir wrote:
Dragon_Hilord wrote:
PS. Also, I can't seem to figure out how to print numbers. What I mean is, it always comes out as a symbole! Thanks ahead. (Could be credited to my kPutChar which handels all printing in the end ::))


Sounds like you have problems with your hex->ascii conversion routine.


;P I don't have one ;,,(


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Tue Mar 15, 2005 5:00 pm 
Thanks pype!!

[edit]
Please note that THIS CODE (and the code in the next post) is the BROKEN stuff and will not run properly if you have the sick desire to test it ;P. The kPrint command just makes a large mess w/ this code.
[/edit]


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Tue Mar 15, 2005 5:02 pm 
Source


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Tue Mar 15, 2005 6:10 pm 
Hex -> ASCII is actually simpler than Hex -> Dec -> ASCII

For each nibble you do:

If it's greater than 9 add 7

Add 48

You now have the ASCII char representing that nibble, so print it.

The only minor complication is dealing with the nibbles from most significant to least significant order (Otherwise the number will be printed in reverse), but that's trivial.


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Wed Mar 16, 2005 8:07 am 
That's great guys. you've really helped ;P

Feel free to use the code in these files I supplies


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Thu Mar 24, 2005 10:33 am 
I read here about "conversion array(s)". What is it and how would I use one?

[edit]
I'm gonna put in the stuff you guys already told me this weekend and if this "conversion array(s)" is better/required, I'll throw it in.
[/edit]

Thanks ahead, Cheers, DH.


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Fri Mar 25, 2005 12:17 am 
I define a conversion array as a sort of lookup table, I can't really think of how to explain it properly, so I'll just show an implementation:
Code:
void printHex(uint32_t num)
{
   const char *HexArray = "0123456789ABCDEF";
   for(int i = 28 ; i > -1 ; i -= 4)
       putchar( HexArray[ (num >> i) & 0xF ] );
}
Essentially what happens here is it grabs a digit from the number being analysed and then looks up the "meaning" in the array to print it. (This implementation is rough [and untested] and could probably be done better)


Top
  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Fri Mar 25, 2005 3:16 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
that "stepping by 4" thing is mysterious. and the test against "-1" is probably as much mysterious. Now, i must admit it has the advantage of working with a simple "putchar".

What i usually do is that those string formatting functions prepare a string which will be later used by a "putstring" function:

Code:
char* append_reg32(char* buffer, unsigned value)
{
    unsigned i;
    for (i=0;i<8;i++) {
        buffer[8-i]=hexdigit[value & 0x0f];
        value=value<<4;
    }
    return buffer+8;
}

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:kPrint [edit]and the future[/edit]
PostPosted: Fri Mar 25, 2005 10:19 am 
ok. That sounds usefull ;D

Cheers, DH.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 98 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group