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:
Screen 2:
Screen 3:
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
Weird string outputting problem
Weird string outputting problem
- Attachments
-
- problems.zip
- (2.7 KiB) Downloaded 48 times
One Tequila, Two Tequila, Three Tequila, Floor!
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Weird string outputting problem
Code: Select all
unsigned char *videoram = (unsigned char*) 0xb8000;
--Troy
- gravaera
- 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
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:
Good luck.
gravaera
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));
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.
- Combuster
- 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
Neither is an answer. And that code is not wrong of itself. The problem is mixing JamesM code and bkerndev:
JamesM did the following:
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.
JamesM did the following:
Code: Select all
location = video_memory + (cursor_y*80 + cursor_x);
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
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.