Thread: read/write directly from VideoRam?

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    6

    read/write directly from VideoRam?

    Hey, can anyone help me understand what the structure of VideoRam is and how to use it? I need to implement some GUI in C and I want to access the VideoRam directly using those far poiners????

    It will be a lot easier if I can understand what this function does?

    void Text( int col, int row, char *text, char color )
    {
    char far *pV;
    int i,len;

    pV=(char far*) 0xb8000000L;
    pV+=row*160+col*2;
    len =strlen(text);
    for( ; *text; pV += 2){
    *pV = *text++;
    }
    pV=(char far*) 0xb8000000L;
    pV+=row*160+col*2+1;
    for( i=0; i<len; i++, pV += 2)
    *pV = color;

    }

    10x a lot

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    First, I'd have to know if that function even works for you. On protected mode systems you can't directly access hardware like that, you'd have to use either the system or specific hardware API. But if I had to guess, I'd say that the function writes 'text' to the screen at 'row'x'col' location and sets the color to 'color'.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    What OS are you using?

  4. #4
    Registered User Dev's Avatar
    Join Date
    Mar 2003
    Posts
    59
    This Line : pV=(char far*) 0xb8000000L;

    Here 0xb8000000L is the base address of Text Mode video memory.


    This Line : pV+=row*160+col*2;

    Here The Text mode is of 80 X 25 size. And each Character on the screen occupies two bytes in video memory. One byte for its scan code (or ASCII I am not sure did it long ago) and other byte for it's attribute like it's color whether it will be blinking or not etc etc.

    So multiplying row by 160 (80 *2 : 80 columns , 2 bytes per column) and adding it two column multiplied by 2 gets you offset to the video memory which is then added to base memory address to get absolute video memory address.

    But as Brighteyes said don't use such thing in your program because such things are now becoming obsolete. Under older compilers you can compile this program but better use specific hardware API or other API's like OpenGL or Direct X.

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    6

    Unhappy ohh well

    ok, 10x a lot

    the program will run under DOS
    I am using Win 2000, however I want the program to run under 98/XP as well. Should I just use the ANSI ESCAPE Sequences then

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: ohh well

    Originally posted by Magica
    ok, 10x a lot

    the program will run under DOS
    I am using Win 2000, however I want the program to run under 98/XP as well. Should I just use the ANSI ESCAPE Sequences then
    A console window within Win2000/98/XP is just that, a console. It is not DOS.

    Checkout MSDN for a bunch of useful console functions, and get yourself a compiler that supports them.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. condition variable on read/write locks
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 04-29-2009, 09:32 AM
  2. Linux SCSI read/write
    By galapogos in forum Linux Programming
    Replies: 1
    Last Post: 12-09-2008, 10:36 AM
  3. How to generate read/write errors?
    By Kernel Sanders in forum C Programming
    Replies: 5
    Last Post: 10-22-2008, 07:17 AM
  4. Input stream directly to structure elements?
    By thenrkst in forum C++ Programming
    Replies: 1
    Last Post: 04-24-2003, 11:43 AM