Page 1 of 1

Writing a char to Video RAM in C

Posted: Sun Aug 18, 2002 2:35 am
by srg
Hi
I have now decided to write my stuff in C and so far the Get and Set cursor actions that I wasn having trouble with in asm are now very easy. I am having a little trouble with printing a charachter to video RAM though. With this function, nothing happends:

void Print_Char(UCHAR ascii_char, UCHAR Page)
{
UINT far *video_ram = (UINT*) 0xB8000;

*video_ram = ascii_char;

}

I am writing this in real mode DOS Turbo C++ (it's a C file). At the moment, I am just wanting to write the argument ascii_char to the very top left had corner of the screen.

What am I doing wrong?

BTW I am not particually experienced with using pointers in a HLL, as in Turbo Pascal and Delphi I never used pointers (never got round to it).

Thanks
Steven Graham

Re:Writing a char to Video RAM in C

Posted: Sun Aug 18, 2002 3:48 am
by Pype.Clicker
hmm, if you're using turbo C, you'd better use the MK_FP macro that will construct a far pointer from a segment and an offset. casting 0xb8000 is likely to produce something like 000b : 8000 or 8000 : 000b, but certainly not b800:0000 as expected ...

Re:Writing a char to Video RAM in C

Posted: Sun Aug 18, 2002 4:40 am
by srg
Right

void Print_Char(UCHAR ascii_char, UCHAR Page)
{
UCHAR far *video_ram = 0;

video_ram = MK_FP(0xB800, 0);
*video_ram = ascii_char;
video_ram++;
*video_ram = 7;

}

With this, the top left char is printed as it should, great, but why is the rest of the screen all red??

Thanks
Steven Graham

Re:Writing a char to Video RAM in C

Posted: Sun Aug 18, 2002 4:53 am
by srg
This is odd

it works perfectly under the IDE, but not at all when run by it's self!

this includes code I have for getting and setting the screen cursor!

Re:Writing a char to Video RAM in C

Posted: Sun Aug 18, 2002 4:57 am
by srg
ahh sorry, my mistake

I'd better set up my turbo C better :-[