Page 1 of 1

Bochs VGA bug?

Posted: Fri Oct 25, 2013 9:07 pm
by teodori
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: Select all

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

Re: Bochs VGA bug?

Posted: Sat Oct 26, 2013 9:58 am
by stlw
Not sure but AFAIR

Code: Select all

color << 8 | string[i]
actually means

Code: Select all

color << (8 | string[i])

Re: Bochs VGA bug?

Posted: Sat Oct 26, 2013 12:36 pm
by sortie
@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/langua ... 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.

Re: Bochs VGA bug?

Posted: Mon Oct 28, 2013 9:03 am
by Combuster
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.