Weird string outputting problem

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.
Post Reply
User avatar
overburn
Member
Member
Posts: 50
Joined: Sun Feb 22, 2009 9:15 am

Weird string outputting problem

Post 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 :)
Attachments
problems.zip
(2.7 KiB) Downloaded 49 times
One Tequila, Two Tequila, Three Tequila, Floor!
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Weird string outputting problem

Post 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
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Weird string outputting problem

Post 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
Last edited by gravaera on Sat May 26, 2012 5:04 pm, edited 1 time in total.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Weird string outputting problem

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Weird string outputting problem

Post 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...
Every good solution is obvious once you've found it.
Post Reply