How poke in Quick-C to PC memory ?

James Buster bitbug at vicom.COM
Tue Jan 31 12:56:22 AEST 1989


In article <193 at ndla.UUCP- platt at ndla.UUCP (Daniel E. Platt) writes:
-In article <6416 at bmc.uu.se-, aring at 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 at vicom.com
--------------------------------------------



More information about the Comp.lang.c mailing list