It is very close - but the line
unsigned short lowerByteAs16bitValue = lowerByte & 0 ;
will clear the lower byte. You probably want
unsigned short lowerByteAs16bitValue = lowerByte;
You don't really need the lowerByte
, and could use c
directly - but your code is more readable.
Next problem:
unsigned short complete16bitValue = higherByteAs16bitValue & lowerByteAs16bitValue ;
Again, you are using the &
operator. I think you mean to use |
(OR) as you did a few lines earlier.
While this now looks "portable", you still need to be careful when writing to the hardware since low-endian and high-endian platforms may switch the byte around - so while your code works up to the point of returning the correct 16 bit word, you may need to pay attention to how that word gets written to the VGA card. That's the line you had commented out... but it is critically important!