OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:11 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Bochs VGA bug?
PostPosted: Fri Oct 25, 2013 9:07 pm 
Offline
Member
Member

Joined: Wed Nov 14, 2012 4:55 pm
Posts: 103
Hello, in bochs displaying a string longer then 5 through VGA buffer doesn't work. If string is greather then 5 the color gest displayed but not the tex. If string is smaller then 6 it works. I it a bochs bug or is it normal for VGA. Here is my function:

Code:
void terminal_write(uint8_t color, uint8_t* string, uint16_t string_len, uint16_t offset){
   uint16_t* tb = (uint16_t*) 0xb8000 + offset;
   uint16_t i;

   for(i = 0; i < string_len; i++)
      tb[i] = color << 8 | string[i];
}


Top
 Profile  
 
 Post subject: Re: Bochs VGA bug?
PostPosted: Sat Oct 26, 2013 9:58 am 
Offline
Member
Member

Joined: Fri Apr 04, 2008 6:43 am
Posts: 357
Not sure but AFAIR

Code:
color << 8 | string[i]


actually means

Code:
color << (8 | string[i])


Top
 Profile  
 
 Post subject: Re: Bochs VGA bug?
PostPosted: Sat Oct 26, 2013 12:36 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
@stlw: Stop spreading lies and look up operator precedence. Everytime you are in doubt, you should look it up, instead of randomly adding unnecessary parentheses. This improves both your code and your coding skills considerably.

The & and | operators are quite loose while << is considerably tighter. For reference, see http://en.cppreference.com/w/cpp/language/operator_precedence. That is, his code does do what is intended in this case.

The main culprit is likely silent promotion to 'int' and the fact that he appears to use uint16_t instead of size_t - or just that his code is so mistaken in the first place that it doesn't work because of something else bad he did.


Top
 Profile  
 
 Post subject: Re: Bochs VGA bug?
PostPosted: Mon Oct 28, 2013 9:03 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
The main culprit is likely silent promotion to 'int' and the fact that he appears to use uint16_t instead of size_t - or just that his code is so mistaken in the first place that it doesn't work because of something else bad he did.
My crystal ball blames the linker script for not adding a .rodata for when the compiler no longer wants to inline longer string printings.

As far as I recall how the graphics code works you can't have a colour/text pair on screen if it hasn't actually existed that way in VRAM at some point.




Also, regarding parentheses, binary shift has varying precedences across programming languages - because it's mostly absent from formal mathematics and the perceived logical use is a subjective thing as a consequence. Also, you should write code to convey the most legible intent - that includes well-placed parentheses rather than the minimum number thereof.

_________________
"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 ]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 29 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group