JamesM tutorial 2 Distortions

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
catron
Posts: 4
Joined: Fri Dec 19, 2008 2:37 am

JamesM tutorial 2 Distortions

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: JamesM tutorial 2 Distortions

Post 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
catron
Posts: 4
Joined: Fri Dec 19, 2008 2:37 am

Re: JamesM tutorial 2 Distortions

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: JamesM tutorial 2 Distortions

Post 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
catron
Posts: 4
Joined: Fri Dec 19, 2008 2:37 am

Re: JamesM tutorial 2 Distortions

Post by catron »

Code: Select all

u8int  attributeByte = (backColour << 4) | (foreColour & 0x0F);
u16int attribute = attributeByte << 8;
u16int *location;
catron
Posts: 4
Joined: Fri Dec 19, 2008 2:37 am

Re: JamesM tutorial 2 Distortions

Post 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:
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: JamesM tutorial 2 Distortions

Post by AJ »

Been there :)

Glad you got it sorted.

Cheers,
Adam
Post Reply