简体   繁体   中英

C : write to video ram

I am trying to make a function that would write strings to video memory with a specific color. However, I am unable to make it work. To write single characters, i would do this:

*(char *)0xb8000 = 'O'; //Prints the letter O at the first position in video memory
*(char *)0xb8001 = 'O'; //Adds it some colors (Haven't figured how to write a byte here)

But I need to write with a variable, so I tried this but it just prints nothing.

int currentAddressVRAM = 0xb8000;

*(char *)currentAddressVRAM = 'O';
currentAddressVRAM++;

*(char *)currentAddressVRAM = 'O';
currentAddressVRAM++;

How would I do this? What am I doing wrong?

Edit: I tried this too and it just printed nothing:

char *currentAddressVRAM = (char *)0xb8000;

*currentAddressVRAM = 'O';
currentAddressVRAM++;

*currentAddressVRAM = 'O';
currentAddressVRAM++;

I found out how to do it finally!
Thanks for all of your helpful comments, it help me find the solution to my problem.
Here is my code :

#define VIDEO_MEMORY 0xb8000

void PrintS(char *text, char color)
{
    char *currentAddressVRAM = (char *)VIDEO_MEMORY;
    for (int i = 0; 1; i++)
    {
        if (text[i] == '\0')
        {
            break;
        }
        *currentAddressVRAM++ = text[i];
        *currentAddressVRAM++ = color;
    }
}

The only problem with this is that I don't know how to save the current address between the uses of the function. If somebody knows, please let me know!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM