Mail Archives: djgpp/1997/02/19/06:23:36
Gregary J Boyles (boylesgj AT lion DOT cs DOT latrobe DOT edu DOT au) wrote:
: I am moving characters + text attribute to a window, which is later copied
: directly to video RAM.
: The window is stored as a 1D array and the text attribute is an unsigned with
: the lower byte zeroed.
: The function :
: void WindowC::Write(char Ch)
: {
: <calcualte array index from cursor coordinates>
: Window[Index]=Attribute | (unsigned)Ch;
: <move the window cursor>
: }
: In one example of using this function I should have seen a light grey
: character on a blue back ground.
: I.E. 0 001 0111 10110011
: | | | |
: | | | +------ASCII 179
: | | +-------------light grey fore ground
: | +------------------blue back ground
: +---------------------non blinking
: Instead I saw a white flashing character on a light grey back ground.
: I.E. 0 001 0111 10110011
: | | | |
: | | | +------ASCII 179
: | | +-------------white fore ground
: | +------------------light grey back ground
: +---------------------blinking
The binary values here are identical (the latter should be 1 111 1111 ...).
: I was assuming that the upper byte would be zeroed in the conversion
: (unsigned)Ch.
: I.E.
: char : 10110011 -----> unsigned : 0000000010110011
: Is this assumption wrong and the upper byte could be anything?
It's *not* anything. What happens here is that your (signed) char is
first *implicitly* cast to (signed) short and then *explicitly* cast to
unsigned short, so the upper byte is all zeros or all ones depending on
the highest bit of the lower byte. You should use (short)(unsigned)Ch.
--
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/
- Raw text -