Microsoft "C" How to Peek and Poke?

Dave Levenson dave at westmark.UUCP
Mon Jul 11 11:29:10 AEST 1988


In article <1148 at cod.NOSC.MIL>, ammons at cod.UUCP writes:
> Question:
...
>    How can a Microsoft "C" programmer read and write the contents of
>    a particular memory location in an IBM-PC compatble (ie. Zenith Z-248)?
>    That is, how can you peek and poke in Microsoft C?


While you could write peek() and poke() functions in MS-C, you can
more efficiently de-reference a far pointer to the absolute memory
location inline.

For example:  Suppose we want to update absolute location B800:0000
(which is the upper left character position on the screen, with the
video adaptor I'm using) and put a character there.  We can write:

void showit(c)
char c;
{
	char far *video;
	FP_SEG(video) = 0xb800;		/* initialize the pointer */
	FP_OFF(video) = 0;
	
	*video = c;			/* update the location */

	return;
}

The above function uses a Microsoft extension of C (it's available
on some other Intel-based compilers, as well): the far pointer. 
This is a pointer consisting of a segment and offset, that is a
"natural object" for the Intel architecture.

-- 
Dave Levenson
Westmark, Inc.		The Man in the Mooney
Warren, NJ USA
{rutgers | att}!westmark!dave



More information about the Comp.lang.c mailing list