Page 1 of 1

JamesM tutorial 2 Distortions

Posted: Fri Dec 19, 2008 2:45 am
by catron
Hello,
First of all, I am just making an simple OS for the heck of it.
So I stumbled upon the series of tutorials by JamesM, and I have compiled his 2nd tutorial (no code modifications)
Under bochs(2.3.7CVS) and qemu(.9.1) I get an odd distortion on the printing of Hello, world!

Code: Select all

Hlowrd!
All characters with different colored backgrounds... I have an idea of what the problem is, but I am unsure of how to fix it.
I also have a hunch it may be because of my 64 bit architecture? I am using the appropriate compiler flags to compile to 32 bit


Thanks,
catron

Re: JamesM tutorial 2 Distortions

Posted: Fri Dec 19, 2008 2:49 am
by AJ
Hi,

It's because each VGA character requires 2 bytes - a colour code and the character data. This means that the VGA is interpreting every other byte of "Hello World!" as a colour code.

Cheers,
Adam

Re: JamesM tutorial 2 Distortions

Posted: Fri Dec 19, 2008 2:55 am
by catron

Code: Select all

location = video_memory + (cursor_y*80 + cursor_x);
*location = c | attribute;
I don't see what is wrong with it then... if the attribute has already been shifted over 8 bits shouldn't the OR combine them?
Sorry, my weakest point of programming is probably bitwise/bitshifting operations.

Thanks,
catron

Re: JamesM tutorial 2 Distortions

Posted: Fri Dec 19, 2008 3:00 am
by AJ
It would depend on context.

Is *location a pointer to a 16 bit wide integer? If you're only incrementing it by a single byte between each character, that could still have the effect you're seeing. Or perhaps c and attribute are only 8 bits wide and the shift isn't doing what you expect because of an overflow (you are using -Wall and -Werror, I assume? Also see Makefile for loads more warning switches).

I can assure you that the VGA works the same on 32 and 64 bit architectures.

Cheers,
Adam

Re: JamesM tutorial 2 Distortions

Posted: Fri Dec 19, 2008 3:03 am
by catron

Code: Select all

u8int  attributeByte = (backColour << 4) | (foreColour & 0x0F);
u16int attribute = attributeByte << 8;
u16int *location;

Re: JamesM tutorial 2 Distortions

Posted: Fri Dec 19, 2008 3:14 am
by catron
Sorry, it seems my object files weren't being updated... so it was working, but I was running the same elf over and over.
:oops: :oops:

Re: JamesM tutorial 2 Distortions

Posted: Fri Dec 19, 2008 4:25 am
by AJ
Been there :)

Glad you got it sorted.

Cheers,
Adam