Page 1 of 1

Weird string outputting problem

Posted: Tue Aug 18, 2009 3:50 pm
by overburn
I have tried to create a barebones kernel with basic screen printing functionality , following these tutorials:
http://jamesmolloy.co.uk/tutorial_html/ ... creen.html
http://wiki.osdev.org/Bare_bones

The only problem is, i have 2 functions which seem do behave extremely odd when put together.
one is "writech(char c)" and the other "write(char *c)"

when i use write("blablabla") i get the scenario in the first picture.
when i use writech('X') i get the scenario in the second picture. this works as it should.
and when i use multiple writech('X') one after another, i get the scenario in the third picture.

Screen 1:
Image
Screen 2:
Image
Screen 3:
Image


and i have no idea how to fix this or why it is doing this. been trying for 3 hours now :(
can anyone help with a hint at least, or a link to where i can find a good print function example?
(i have attached the source code in the post)
thanks :)

Re: Weird string outputting problem

Posted: Tue Aug 18, 2009 4:02 pm
by Troy Martin

Code: Select all

unsigned char *videoram = (unsigned char*) 0xb8000;
This is wrong. I'll leave it to you to figure it out.

--Troy

Re: Weird string outputting problem

Posted: Tue Aug 18, 2009 4:27 pm
by gravaera
Well, his code is not bad, so it seems he's a textbook type. They wouldn't have taught all the intricacies at Uni, so:

Strings are of type const char *, and not const unsigned char *. There's a bit of logic to this. Either way, a better, and in the end, more convenient solution for referencing the VGA memory framebuffer would be (for text mode) something of the form:

Code: Select all

struct vga_text_framebuffer_t
{
	char			_char;
	unsigned char	_attr;
} __attribute__((packed));
Good luck.
gravaera

Re: Weird string outputting problem

Posted: Wed Aug 19, 2009 5:47 am
by Combuster
Neither is an answer. And that code is not wrong of itself. The problem is mixing JamesM code and bkerndev:

JamesM did the following:

Code: Select all

location = video_memory + (cursor_y*80 + cursor_x);
which is not wrong either. Or it is. In either case, both assume something about the other.

video_memory is a pointer. A pointer + something is equivalent to &(pointer[something])
if pointer is byte-sized, the result is a displacement of x bytes. if pointer is 16-bit sized, the real displacement is twice as large with the same offset. Each VGA character is two bytes. You currently move only one byte per character. Pix your fix of choice.

If you'd enable warnings (which is a Good Thing(tm) ), you get a nice list of errors relating to the conversion of byte pointers to word pointers allowing you to spot that problem and many others in advance.

Re: Weird string outputting problem

Posted: Wed Aug 19, 2009 6:23 am
by Solar
Oh, and it would be nice if, next time, you'd cut your screenshots down to the relevant sections. As nice as your mountain wallpaper is, I don't feel like downloading it three times in a resolution twice as wide as my monitor (three clicks and a scroll right each time), when the useful information it contains would fit in a thumbnail...