[comp.lang.c] How poke in Quick-C to PC memory ?

aring@bmc.uu.se (01/24/89)

How do you poke, in quick-C, to a memory adress on a PC ?
Equivalently, how do you set a pointer to point to, say, the base of
a memory mapped I/O board ? 
gratefull for help, Avi Ring.

platt@ndla.UUCP (Daniel E. Platt) (01/29/89)

In article <6416@bmc.uu.se>, aring@bmc.uu.se writes:
> How do you poke, in quick-C, to a memory adress on a PC ?
> Equivalently, how do you set a pointer to point to, say, the base of
> a memory mapped I/O board ? 
> gratefull for help, Avi Ring.

If the address is addr (type long) such as

	0x010023afL

where the above refers to location 0100:23af
and you want to put a data type 'foo' there, you can refer to
that memory as (foo *)0x010023afL.

Dan Platt

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
||								 ||
||	Dan Platt			1(914)941-2474 		 ||
||	Watson (IBM)			PLATT@YKTVMV.BITNET 	 ||
||			..!uunet!bywater!scifi!ndla!platt 	 ||
||								 ||
||	The opinions expressed here do not necessarily reflect	 ||
||		those of my employer!				 ||
||								 ||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

bitbug@vicom.COM (James Buster) (01/31/89)

In article <193@ndla.UUCP- platt@ndla.UUCP (Daniel E. Platt) writes:
-In article <6416@bmc.uu.se-, aring@bmc.uu.se writes:
-- How do you poke, in quick-C, to a memory adress on a PC ?
-- Equivalently, how do you set a pointer to point to, say, the base of
-- a memory mapped I/O board ? 
-- gratefull for help, Avi Ring.
-
-If the address is addr (type long) such as
-
-	0x010023afL
-
-where the above refers to location 0100:23af
-and you want to put a data type 'foo' there, you can refer to
-that memory as (foo *)0x010023afL.

Another solution is the following:

/*
 * MAKE FAR POINTER:
 *	macro to create a far pointer to a given segment and offset
 */
#define MK_FP(segment,offset)\
	((void far *) (((unsigned long) (segment) << 16) + (offset)))

Add the approriate type cast, i.e.:

#define EGA_SEGMENT	(0xa000)
#define EGA_RAM_OFFSET	(0x0000)
char *device_ptr = (char *) MK_FP (EGA_SEGMENT, EGA_RAM_OFFSET);

and presto, you have a pointer pointing anywhere you want.

--------------------------------------------
	     James Buster
	Mad Hacker Extraordinaire
    	...!ames!vsi1!bitbug
	   bitbug@vicom.com
--------------------------------------------

geoff@warwick.UUCP (Geoff Rimmer) (02/01/89)

In article <6416@bmc.uu.se> aring@bmc.uu.se writes:
>How do you poke, in quick-C, to a memory adress on a PC ?

poke?  what does that mean? :-)

Geoff

	------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, England.
			geoff@uk.ac.warwick.emerald

	"BASIC screws you up"
	------------------------------------------------------------