如何使用 Const Char* 打印 ASCII 扩展字符?

发布于 2024-08-19 09:11:51 字数 513 浏览 7 评论 0原文

我有一个在屏幕上打印字符的函数,如下所示:

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++;
   }
}

我想打印字符 十进制的 254,但我需要使用存储在 const char* 上。我无法尝试 print(0x0F, 0, 0, 0xFE);,因为这会在没有强制转换的情况下引发指针错误,那么我该怎么做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月依秋水 2024-08-26 09:11:51

使用 C 的十六进制表示法将字符嵌入字符串中:

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

正如人们所指出的,您可能想要稍微美化一下代码,也许可以通过为 VGA 帧缓冲区基地址

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.

ぶ宁プ宁ぶ 2024-08-26 09:11:51

这是题外话,对此的回忆,但是挖掘代码我发现了这个:

/* 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('?');
}

希望这有帮助,
此致,
汤姆.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文