I have a function to print characters on the screen that is like this:
void print(int colour, int y, int x,开发者_JAVA百科 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?
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.
This is off-topic, memories of this, but digging up the code I found this:
/* Global Variables */
static Word far *ScrPtr;
/* Local Variables */
static Word VidSeg;
...
int WinScreenHeight(void)
{
return (*(unsigned char far *) 0x484) + 1;
}
int WinScreenWidth(void)
{
return (*(unsigned int far *) 0x44A);
}
void WinInit(){
SetMode(AdapterType());
ScrPtr = (Word far *) CreateFarPtr(VidSeg, 0x0000);
}
static void SetMode(int VideoAddress)
{
switch(VideoAddress)
{
case VGA :
case MCGA:
case EGA :
case CGA : (Word) VidSeg = 0xB800;
break;
case MDA : (Word) VidSeg = 0xB000;
break;
case '?' : fprintf(stderr, "Sorry Unknown Video Adapter.\n");
fprintf(stderr, "This program requires C/E/MC/VGA, Mono Adapter\n");
exit(1);
}
}
static int AdapterType(void)
{
char far *VidMode;
char blreg, alreg;
VidMode = (char far *) 0x00000449L;
asm mov ax, 0x1a00;
asm push bp;
asm int 0x10;
asm pop bp;
asm mov blreg, bl;
asm mov alreg, al;
if (alreg == 0x1a && blreg >= 9) return(MCGA);
if (alreg == 0x1a && blreg >= 7 && blreg <= 9) return(VGA);
if (blreg == 4 || blreg == 5) return(EGA);
if (*VidMode == 3) return(CGA);
if (*VidMode == 7) return(MDA);
return('?');
}
Hope this helps, Best regards, Tom.
加载中,请稍侯......
精彩评论