[英]How To Print ASCII Extended Characters Using a Const Char*?
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*
. 我想将字符254打印为十进制 ,但是我需要使用存储在const char*
上的const char*
。 I can't try print(0x0F, 0, 0, 0xFE);
我无法尝试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: 使用C的十六进制符号将字符嵌入字符串:
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 . 正如人们所指出的那样,您可能想稍微完善一下代码,也许通过为VGA帧缓冲基址添加符号名来实现。
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. 希望这对您有所帮助,汤姆,谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.