Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!umd5!uvaarpa!virginia!babbage!mac3n From: mac3n@babbage.acc.virginia.edu (Alex Colvin) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: Looking for C functions to access PC memory Message-ID: <127@babbage.acc.virginia.edu> Date: Fri, 13-Nov-87 10:13:32 EST Article-I.D.: babbage.127 Posted: Fri Nov 13 10:13:32 1987 Date-Received: Sun, 15-Nov-87 16:38:08 EST References: <24261F3U@PSUVMB> <6662@brl-smoke.ARPA> Organization: University of Virginia Lines: 34 Summary: questionable cast Xref: mnetor comp.sys.ibm.pc:10151 comp.lang.c:5412 > #define PEEK(loc) (*(char *)(loc)) > #define POKE(loc,value) *(char *)(loc) = (value) > > To access a wide datum than a byte, change "char" to "short" or "long". These will work in SOME program models with SOME compilers. In the small model, a (char *) can only point within the data segment. What's probably wanted here is a pointer that can reach anywhere in memory. Because this issue isn't well defined by PDP-11 C, most PC compilers have their own way of doing this. In CII's C86 there is the movblock routine, whose arguments are offsets and segments. In uSoft C you can declare (char far*) pointers, which can point outside your data segment. Casting (loc) to a pointer is unreliable. The meaning of a such a cast is not well-defined. If loc is a 16-bit int or short, this won't get you beyond the data segment, but is probably reliable for references (offsets) within it. If loc is a 32-bit int or long (depends on your compiler), it can hold a full address. Now the question is, what's an address? Some compilers view such a cast as a simple trick on the type system, in which case (loc) should consist of a segment in the most significant 16 bits and an offset in the least significant 16 (the actual format of a far pointer). Other compilers try to make casts into conversions, and assume (loc) is a 32-bit offset from the beginning of memory, in which case (loc) has the segment number * 16 + the offset, in 32 bits. Best to find out what your compiler manual tells you. Then decorate the code with warnings and #ifdefs been burned before... mac@cs.virginia.edu