home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14763 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  3.5 KB

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!jvnc.net!rutgers!zeus.ieee.org!fsbbs!f204.n2603.z1.ieee.org!Ray.Arachelian
  2. From: Ray.Arachelian@f204.n2603.z1.ieee.org (Ray Arachelian)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Patching CODE resources
  5. Message-ID: <15796.2AA153CD@zeus.ieee.org>
  6. Date: 29 Aug 92 17:43:04 GMT
  7. Sender: news
  8. Organization: FidoNet node 1:2603/204 - Not Even Odd, Forest Hills NY
  9. Lines: 82
  10.  
  11. In regards to my previous post about ZBasic speed problems, I've narrowed
  12. down the problem a bit.  Perhaps someone familiar with patching applications
  13. or with the inner workings of _WaitNextEvent could help with this?
  14.  
  15. Let me assure you that I do own and have Think C before anyone suggests that
  16. I dump my Zbasic compiler and switch to C. :-)  (Actually this would not
  17. be a bad idea.)
  18.  
  19. I've experimented with Zbasic and found it to slow down tremendously under
  20. system 7, however it would work at normal fast speed under older systems.
  21.  
  22. I didn't know what the problem was until I built a bench mark progam which
  23. tested a lot of things including printing and event handling.
  24.  
  25. The major difference was indeed event handling.  It seems ZBasic produces
  26. code that calls _SystemTask and _GetNextEvent.  I've tried to build a patch
  27. to the code procedures that call these routines to force ZBasic to call
  28. _WaitNextEvent instead however the program crashes...
  29.  
  30. My question: Does anyone know how to append code at the end of a resource
  31. so it does not interfere with the rest of the program?  (I take it that
  32. either something is jumping in the middle of my patch, or the segment
  33. loader can't deal with extra code being appended to the end of a segment.)
  34.  
  35. My patch looks something like this:
  36.  
  37. Zbasic code resource5, Anon procedure 291.
  38.  
  39.   MOVEM.L D1/D2/A0/A1,-(A7)
  40.   SUBQ.L #$2,A7                 // Make space on stack for return val?
  41.   MOVE.W #$0fff,-(A7)           // Event Mask
  42.   PEA    -$0786(a5)
  43.   _GetNextEvent
  44.   TST.B  (A7)+                  // Check return value on stack.
  45.   /\/\/\/\/\/\/\/\/\/\/\/\/\
  46.  
  47. There is also another procedure that calls GNE with a keyboard mask, and
  48. it is only used to get keypressess.   It is similar to the one above.
  49.  
  50. There are also pieces of code which check the timer and call _SystemTask.
  51.  
  52. I've tried several patches to the code, and they look mostly like this:
  53.  
  54.   MOVEM.L D1/D2/A0/A1, -(A7) // same
  55.   SUBQ.L #$2,A7
  56.   MOVE.W #$0fff,-(A7)       // same
  57. xxx:
  58.   JMP    code5+$780C       // jump to my code
  59.   BRA.S  xxx
  60. yyy:
  61.   TST.B (A7)+
  62.  
  63. The JMP replaces the PEA instruction above, the BRA branches to the JMP
  64. incase of any other code resource jumping in the middle of my patch and
  65. possibly causing a crash.
  66.  
  67. At code5+$780c my patch looks like this:
  68.  
  69.   MOVE.L #$00000007,-(A7)  // Push sleep value
  70.   CLR.L -(A7)              // Push zero for MouseRgn value
  71.   _WaitNextEvent
  72.   JMP yyyy
  73.  
  74. I applied this patch to both calls to _GetNextEvent (I duplicated the patch
  75. twice, so I have two return jumps.) I didn't want to use JSR/RTS as they
  76. would place the return values returned by _WaitNextEVent in a differnet
  77. location on the stack.  I also NOP'ed out all calls to _SystemTask, yet
  78. the application crashes.  Sometimes it starts to work for one pass and
  79. then when it restarts, it crashes.  What did I overlook?
  80.  
  81. Thanks for your patience.
  82.  
  83.  -- Ray
  84. (P.S. If you could send a response to rarachel@ishara.poly.edu, this would be
  85. preferred since I'd get your reply about a week ahead of the
  86.  
  87. internet<->fidonet exchange.)
  88.  
  89.  
  90. --  
  91. =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  92.  Ray Arachelian - Internet: Ray.Arachelian@f204.n2603.z1.ieee.org
  93.