In C, how do I write to a particular memory location e.g. video memory b800, in DOS (real DOS, MS DOS 6.22)
I understand that C doesn't have anything built in to do that, but that there may be some platform specific e.g. DOS specific API functions that can.
A small demo program that does it would be great.
I have Turbo C (TCC.EXE - not tiny c compiler, Turbo C compiler)
I know debug can do it (e.g. some of the tiny bit of debug that I know) -f b800:0 FA0 21 CE
(that writes some exclamation marks to the command line). But i'd like a C program to write to b800:0
The address b800:0000
uses a segment of 0xb800
and an offset of 0x0000
. This corresponds to the linear address 0xb8000
(note the extra 0
, as the segment is shifted left by 4 bits).
To create a pointer to this address in protected mode, you'd use
char *p = (char *)0xb8000;
However, you are most likely in real mode, so you need to construct a far pointer:
char far *p = (char far *)0xb8000000;
The 32 bit value is split in two 16 bit values, which are assigned to segment and offset.
You can use this pointer normally, then:
*p = '!';
Can you try this (untested as I don't have my old PC)
char far* video = 0xb8000000L;
*(video++) = '!';
*(video++) = 0x0A;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With