home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22067 < prev    next >
Encoding:
Text File  |  1993-01-24  |  2.6 KB  |  66 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!gumby!kzoo!k044477
  3. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  4. Subject: Re: Question about bit manipulation
  5. Message-ID: <1993Jan24.173648.5148@hobbes.kzoo.edu>
  6. Organization: Kalamazoo College
  7. References: <1993Jan24.023728.5051@afterlife.ncsc.mil>
  8. Date: Sun, 24 Jan 1993 17:36:48 GMT
  9. Lines: 55
  10.  
  11. mssmith@afterlife.ncsc.mil (M. Scott Smith) writes:
  12. >
  13. >Basically, I write to the screen by doing something like this:
  14. >long *long_ptr;
  15. >long_ptr = (address of memory location representing part of screen to draw to)
  16. >*long_ptr = 0xaaaaaaaa;
  17. >
  18. >   All works well.  I have developed a system for converting pictures into
  19. >this format, so I can easily (and VERY quickly!) plot these pictures on screen.
  20.  
  21. OK, if it works well, I won't give you the standard didacticism about
  22. (1) stripping your addresses, but not the screen's address, (2) calling
  23. SwapMMUMode(), (3) calling ShieldCursor(), and (4) never assuming that
  24. the screen's rowBytes is anything other than
  25. ((**(**theGDevHndl).gdPMap).rowBytes & 0x3FFF).
  26.  
  27. :-)
  28.  
  29. >But, now I want to replace all "00"'s with the color from the background at
  30. >that location..  So, if the first four pixels of the screen look like this:
  31. >a1a1a1a1
  32. >And I want to plot a "ee0000ee" on the screen, I would want the result to be:
  33. >eea1a1ee
  34. >Now, the way that I'm attacking this, is to basically
  35. >bit-or the two together.
  36. >I.e. "ee0000ee | 00a1a100" should yield "eea1a1ee", which is what I want.
  37.  
  38. Yep, assuming you managed to pull 00A1A100 off the screen OK.  If I were
  39. in a pedantic mood, I'd point out that the most obvious method,
  40. (*long_ptr) & (~0xEE0000EE), doesn't work;  you need to make up a mask,
  41. each byte of which is either 00 or FF.
  42.  
  43. >But the problem is, Think C doesn't seem to want to deal with long's greater
  44. >than four hexadecimal digits..  That is, if I do:
  45. >  printf("%x\n", 0xffffffff);
  46. >It prints:
  47. >  ffff
  48.  
  49. This sounds like a printf-related problem.  You probably have to use
  50. "%lx" to print long hex values, or declare your ints to be four-byte, or
  51. sacrifice a boar to the moon goddess, or something--printf can get
  52. pretty confusing and I don't claim to understand it.
  53.  
  54. >  unsigned long int junk = 4147483645;
  55. >  printf ("[%ld]\n", junk);
  56. >It prints out "-147483651"..
  57.  
  58. Well, that's the signed equivalent of junk.  (-147483651 + (2^32) equals
  59. 4147483645.)  Try sticking a "u" somewhere after the "%", or maybe
  60. chanting "Dalai Lama" while your program compiles.
  61. -- 
  62.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  63.  "So since You do NOT hold to The Warriors Code,
  64.   it is OBVIOUS that you do NOT have worthwhile Values."
  65.     - drieux
  66.