Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!nrl-cmf!cmcl2!brl-adm!brl-smoke!gwyn
From: gwyn@brl-smoke.ARPA (Doug Gwyn )
Newsgroups: comp.lang.c
Subject: Re: Microsoft "C" How to Peek and Poke?
Keywords: Peek Poke
Message-ID: <8230@brl-smoke.ARPA>
Date: 9 Jul 88 04:45:01 GMT
References: <1148@cod.NOSC.MIL>
Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) )
Organization: Ballistic Research Lab (BRL), APG, MD.
Lines: 19

In article <1148@cod.NOSC.MIL> ammons@cod.NOSC.MIL (Tempest P. Ammons) writes:
>   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?

If you really must stoop to such a disgusting habit, the following
approach should work on any reasonable C implementation on any system
that does not use memory mapping.  (For 80x86 implementations, you may
need to resort to kludgery such as using a "far" keyword; I don't
program those critters so I'm not 100% familiar with all the crocks
that typical 80x86 implementations seem to force on you.)

	#define	PEEK_8( byte_loc )	(*(char *)(byte_loc))
	#define	PEEK_16( word_loc )	(*(short *)(word_loc))
	#define	POKE_8( loc, byte )	((void)(*(char *)(loc) = byte))
	#define	POKE_16( loc, word )	((void)(*(short *)(loc) = word))

Usage:
	if ( PEEK_8( 0xFF00 ) != 0x80 )
		POKE_16( 0xF080, 0x1000 );