Page 2 of 2

Re: Some ASM questions

Posted: Mon Nov 10, 2008 5:44 pm
by Qoppa
OK, thanks. Just wanted to be sure I wasn't missing something important.

The code for my puts function:

Code: Select all

word *screenmem = (word *) 0x000B8000;

void puts(const char *str)
{
	int i;
	for(i = 0; i < strlen(str); i++)
		memsetw(screenmem + i, (color << 8) | str[i], 1);
}
It prints it just fine. The text just flickers...

Re: Some ASM questions

Posted: Mon Nov 10, 2008 6:53 pm
by Combuster
Qoppa wrote:(written by someone on this board... I forget who)
If you bothered to look at the link...
Just to note, there's also a DX there (which is not quite a byte...)

As for your code: there are signed conversions, and color can have bit 7 set which causes blinking as well - try a black background.

Re: Some ASM questions

Posted: Mon Nov 10, 2008 7:24 pm
by Qoppa
Combuster wrote:As for your code: there are signed conversions, and color can have bit 7 set which causes blinking as well - try a black background.
That was it, thank you!

Sorry for not remembering who's signature I found the site in. As a beginner, it's really useful/interesting to look through.

Re: Some ASM questions

Posted: Mon Nov 10, 2008 7:28 pm
by CodeCat
If the most significant bit is set, it can be interpreted as both blinking text and brighter background depending on a setting in the VGA I/O memory area. If the blinking is fast (Bochs by default has a rather high blink rate) then it looks like what you described. It's also best to use specifically unsigned quantities, especially with char. Char is not required to be either signed or unsigned, so you should always specify it if you depend on its (lack of) signedness. And as Combuster said, if a signed value is casted to a larger value, it is sign-extended, which will result in extending the value with 1-bits if the original value had its most significant bit set. I.e. 8 bits 1000 0001 (-127 signed, 129 unsigned) is sign-extended to 16 bits 1111 1111 1000 0001 (-127 signed, 65409 unsigned).

Also, what type does color have? If it's a char, then shifting it left by 8 places will shift all the bits off the end, and you get zero. You need to cast it to a short first before shifting so that there is additional room for the shift.

I assume that you didn't get around to handling cursor position, newlines and scrolling yet.