OSDev.org
https://forum.osdev.org/

Bochs VGA bug?
https://forum.osdev.org/viewtopic.php?f=2&t=27298
Page 1 of 1

Author:  teodori [ Fri Oct 25, 2013 9:07 pm ]
Post subject:  Bochs VGA bug?

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];
}

Author:  stlw [ Sat Oct 26, 2013 9:58 am ]
Post subject:  Re: Bochs VGA bug?

Not sure but AFAIR

Code:
color << 8 | string[i]


actually means

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

Author:  sortie [ Sat Oct 26, 2013 12:36 pm ]
Post subject:  Re: Bochs VGA bug?

@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.

Author:  Combuster [ Mon Oct 28, 2013 9:03 am ]
Post subject:  Re: Bochs VGA bug?

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/