views:

297

answers:

2

I have a function to print characters on the screen that is like this:

void print(int colour, int y, int x, const char *string)
{
   volatile char *video=(volatile char*)0xB8000 + y*160 + x*2;
   while(*string != 0)
   {
      *video=*string;
      string++;
      video++;
      *video=colour;
      video++;
   }
}

And I want to print the character 254 in decimal, but I need to use stored on a const char*. I can't try print(0x0F, 0, 0, 0xFE);, because this trows a error of pointer without cast, then how can I do this?

+3  A: 

Embed the character in the string using C's hex notation:

print(0x0f, 0, 0, "\xfe");

As folks have pointed out, you might want to pretty up the code a bit, perhaps by adding a symbolic name for the VGA framebuffer base address.

unwind
+1  A: 
tommieb75
This is too much helpful! I'm going to save this code to take a better look. Thanks very much! **:-)**
Nathan Campos
@Nathan: I'm curious - why? :) Those old skool stuff gave me happy memories... :)
tommieb75
@Nathan: I can provide more code if I can dig out some more code...drop a line here eh? :) ;)
tommieb75