English 中文(简体)
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*. 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.
");
                    fprintf(stderr, "This program requires C/E/MC/VGA, Mono Adapter
");
                    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.





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签