home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18611 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.4 KB  |  67 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!aries.scs.uiuc.edu!mcdonald
  3. From: mcdonald@aries.scs.uiuc.edu (J. D. McDonald)
  4. Subject: Re: Peek/Poke in C
  5. References: <BV5XVB5w165w@blackwlf.gwinnett.com> <pal.724673747@regent.e-technik.tu-muenchen.de> <BzGIDn.Ho4@news.cso.uiuc.edu>
  6. Message-ID: <mcdonald.621@aries.scs.uiuc.edu>
  7. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  8. Organization: UIUC SCS
  9. Date: Fri, 18 Dec 1992 14:36:14 GMT
  10. Lines: 55
  11.  
  12. In article <BzGIDn.Ho4@news.cso.uiuc.edu> cad28526@uxa.cso.uiuc.edu (Chuck Douglas) writes:
  13.  
  14. >pal@regent.e-technik.tu-muenchen.dbp.de (Peter Loibl) writes:
  15.  
  16. >>ericwebb@blackwlf.gwinnett.com (eric webb) writes:
  17.  
  18. >>>Hi again.. does anyone know how to do equivalent of BASIC's PEEK & POKE
  19. >>>statements in C?
  20.  
  21. >>I am sorry for my ignorance, but what are PEEK and POKE doing? If you
  22. >>describe their task, then this would be lots of help for all the
  23. >>"C-Gurus" here.
  24.  
  25. >PEEK and POKE are used in Applesoft BASIC to look at (PEEK) the contents
  26. >of or put (POKE) a value in to a specific memory address.  I really
  27. >don't believe that there is anything analogous to it in C.  At least
  28. >nothing that would serve the use it does in Applesoft.
  29.  
  30.  
  31. Peek and Poke exist (existed) in far more than just one particular Basic.
  32. They are  (were) near ubiquitous. For example, there were in PDP-11
  33. RT11 **system** subroutines (they were not, however, system **calls**,
  34. as they did not call the OS) called IPEEK and IPOKE, not to mention ISPY.
  35.  
  36. And, of course, the original poster had the correct answer! These calls
  37. are used or OS sorts of things, e.g. writing to device registers. 
  38. Any subroutine written in C for the purpose  of being a device driver for
  39. a machine with memory mapped IO or IO vectors will need them.
  40.  
  41. AND FOLKS, PLEASE, don't go blathering about "portability". It makes you
  42. look silly. If the address of something on you computer is 13556, that's 
  43. what it is, and you have no choice about using it.
  44.  
  45. The answer is "if you can do it at all in C, you cast the address to
  46. a pointer of the proper sort and access that pointer ...
  47.  
  48. *(char _far *)(13556) = 17;
  49.  
  50. or value = *(char _far  *)(13556); "
  51.  
  52. where the _far implies you are running a PC in 16 bit mode. 
  53.  
  54. On some computers you can do this only if the address is within some 
  55. annointed range. But remember, you purists out there, this likely **IS**
  56. kernal code. You likely **can** address anywhere you want to!
  57.  
  58.  
  59. Doug McDonald
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.     
  67.