Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C, how do I write to a particular memory location e.g. video memory b800, in DOS (real DOS, MS DOS 6.22)

Tags:

c

dos

turbo-c

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

like image 299
barlop Avatar asked Oct 06 '15 14:10

barlop


2 Answers

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 = '!';
like image 200
Simon Richter Avatar answered Sep 26 '22 01:09

Simon Richter


Can you try this (untested as I don't have my old PC)

char far* video = 0xb8000000L;
*(video++) = '!';
*(video++) = 0x0A;
like image 38
fjardon Avatar answered Sep 25 '22 01:09

fjardon