home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mac / programm / 12771 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  3.5 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!dog.ee.lbl.gov!network.ucsd.edu!ucsbcsl!mcl!scott
  2. From: scott@mcl.ucsb.edu (Scott Bronson)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Stymied++!  VBL Cursor Watching ideas?
  5. Keywords: VBL Cursor
  6. Message-ID: <scott.711700485@mcl>
  7. Date: 21 Jul 92 06:34:45 GMT
  8. Sender: news@ucsbcsl.ucsb.edu
  9. Lines: 74
  10.  
  11. (The postincrement represents the minor cookie at the end of this letter.)
  12.  
  13. I've run into a real snag with my cursor-watching VBL idea (that I posted
  14. to the 'net a few days ago--it may be archived if the article has expired).
  15. Basically, I cannot see a good way to make my code future-compatible without
  16. taking an incredible performance hit.  Here are the ways that I have tried:
  17.  
  18. The first way I tried was the fastest.  I was getting upwards of 170 iterations
  19. per tick by PPosting() an event, checking the event's modifiers field that got
  20. filled in, then flushing it.  A lot of people frowned on this idea, so I tried
  21. a few other techniques.  Unfortunately, none performed better.
  22.  
  23. OSEventAvail and EventAvail are out.  I cannot get more than 48 iterations per
  24. tick using OSEventAvail, and EventAvail ended up somewhere around eight iters
  25. per tick.  Totally unacceptable if they are to be VBLs because they'd probably
  26. suck up more cycles than save.
  27.  
  28. GetKeys runs in great time.  I can get 127 iterations per tick using some
  29. cool key-watching code that I came up with.  Then I decided that I shouldn't
  30. just *assume* that GetKeys can be called from a VBL.  I was astounded that it
  31. can't!  Such a fast, low-level call that may move or purge memory?!?  Rats.
  32.  
  33. So, I'm stuck.  Here are my options as I see them now:
  34.  
  35. o Use my super-fast first idea of posting and always flushing the event, hoping
  36.   that because the event is always flushed and because the event gets posted
  37.   and removed by a VBL, the system will not be able to choke on it.
  38. o Use some slow code based on OSEventAvail that I have up and running, but can
  39.   only get 48 iterations per tick (on a IIci).
  40. o Patch some other trap (GNE?) so that I can use my sufficiently fast GetKeys
  41.   code.  Problem is, your traps get disabled when your app gets switched out.
  42. o Use some other solution that I haven't thought of yet (and you're going to
  43.   tell me :-).
  44.  
  45. I'd like to hear what you guys think would be best.  Right now I think I'll
  46. keep using the first code that I posted, but waking up my application with
  47. WakeUpProcess() rather than leaving the app1 event in the queue.  Am I
  48. overlooking something obvious?  Is it possible and future compatible to
  49. install a patch that will not be removed when my app switches out?
  50.  
  51. Pipe Dream: Obviously PPostEvent can get at the current state of the
  52. modifiers super-quick and at VBL time.  Is it possible for me to do the
  53. same?
  54.  
  55. Just doing my part to save precious machine cycles...
  56.  
  57.     - Scott
  58.  
  59.  
  60. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61.  
  62. I thought it would be a real shame that my tuned key-watching code would
  63. go unused, so I'm hoping that someone else may find it useful.  If you do
  64. use it, all I ask is that you mail me a short letter telling me how.  I will
  65. support this code if you have any questions.  This code is now public domain.
  66.  
  67.     short gOldKeys = 0L; // Global var holding current state of modifiers
  68.  
  69.     Boolean ModifiersChanged( void )
  70.     {
  71.         KeyMap km;
  72.         register Boolean on = false;
  73.         asm {
  74.             PEA    km
  75.             GetKeys
  76.             MOVE.L    km[1],D1
  77.             ANDI.W    #0x800F,D1
  78.             CMP.W    gOldKeys,D1
  79.             BEQ.S    @exit
  80.             MOVE.W    D1,gOldKeys
  81.             MOVEQ    #1,on
  82.         @exit:
  83.         } return on;
  84.     }
  85.