Writing a char to Video RAM in C

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
srg

Writing a char to Video RAM in C

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Writing a char to Video RAM in C

Post 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 ...
srg

Re:Writing a char to Video RAM in C

Post 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
srg

Re:Writing a char to Video RAM in C

Post 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!
srg

Re:Writing a char to Video RAM in C

Post by srg »

ahh sorry, my mistake

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