OSDev.org
https://forum.osdev.org/

kPrint [edit]and the future[/edit]
https://forum.osdev.org/viewtopic.php?f=1&t=10319
Page 1 of 1

Author:  dh [ Tue Mar 15, 2005 10:43 am ]
Post subject:  kPrint [edit]and the future[/edit]

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 ::))

Author:  Curufir [ Tue Mar 15, 2005 12:24 pm ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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.

Author:  Pype.Clicker [ Tue Mar 15, 2005 12:30 pm ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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 ...

Author:  dh [ Tue Mar 15, 2005 4:59 pm ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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 ;,,(

Author:  dh [ Tue Mar 15, 2005 5:00 pm ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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]

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

Source

Author:  Curufir [ Tue Mar 15, 2005 6:10 pm ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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.

Author:  dh [ Wed Mar 16, 2005 8:07 am ]
Post subject:  Re:kPrint [edit]and the future[/edit]

That's great guys. you've really helped ;P

Feel free to use the code in these files I supplies

Author:  dh [ Thu Mar 24, 2005 10:33 am ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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.

Author:  AR [ Fri Mar 25, 2005 12:17 am ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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)

Author:  Pype.Clicker [ Fri Mar 25, 2005 3:16 am ]
Post subject:  Re:kPrint [edit]and the future[/edit]

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;
}

Author:  dh [ Fri Mar 25, 2005 10:19 am ]
Post subject:  Re:kPrint [edit]and the future[/edit]

ok. That sounds usefull ;D

Cheers, DH.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/