Bochs VGA bug?

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Bochs VGA bug?

Post 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];
}
stlw
Member
Member
Posts: 357
Joined: Fri Apr 04, 2008 6:43 am
Contact:

Re: Bochs VGA bug?

Post by stlw »

Not sure but AFAIR

Code: Select all

color << 8 | string[i]
actually means

Code: Select all

color << (8 | string[i])
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Bochs VGA bug?

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bochs VGA bug?

Post 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.
"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 ]
Post Reply