home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilss / slofilter / SlowFilter (.txt) < prev   
RISC OS BBC BASIC V Source  |  1993-02-21  |  3KB  |  83 lines

  1.  >SlowFilter
  2.  By Jason Williams 1993
  3.  Experimental program to filter out some NULL events from a
  4.  given task. Currently set to permanently do this for one app, and
  5.  allows a MAXIMUM of 1 NULL every half second to get through.
  6.  Undelivered NULLs are converted into events of type 42 (hack)
  7.  No attempt has been made to make this code efficient.
  8.  Usage: Run this program, and then launch another application
  9.  (e.g. Draw), and then try doing anything that sits on NULLs
  10.  (e.g. draw a set of lines - notice how drag updates happen only
  11.  at half-second intervals?)
  12.  Notice that other operations (e.g. typing in some text) are
  13.  totally unaffected.
  14.  This thus demonstrates how a backgrounded task can be slowed to
  15.  allow other applications to get more CPU time.
  16.  Run this program at your own risk. (It runs fine on my machine though)
  17.  b% 256
  18. $b%="TASK"
  19.  "Wimp_Initialise", 200, !b%, "SlowDown Init" 
  20.  ,mytaskid%
  21.  Assemble a bit of code into the RMA (must be permanently paged in)
  22.  "OS_Module",6,,,100 
  23.  ,,code%;flags%
  24.  code%<1 
  25.  flags%<>6 
  26.  42 "Not enough room in RMA":
  27. P%=code%
  28. [ OPT 0
  29.  .lasttime:EQUD 0
  30.  .r1store: EQUD 0
  31.  .r2store: EQUD 0
  32.  .r14store:EQUD 0
  33.   ALIGN
  34.  .filter
  35. *Q  CMP R0, #0                   ; Is this a NULL event? Let all others through
  36. +J  MOVNE PC, R14                ; (this could un-sleep an application?)
  37. -E  STR R1,  r1store             ; Save regs which we must preserve
  38.   STR R2,  r2store
  39.   STR R14, r14store
  40. 1   SWI "OS_ReadMonotonicTime"
  41.   LDR R1, lasttime
  42. 3S  SUB R1, R0, R1               ; Yeah, I know, a 1 in 10 billion chance of this
  43. 4P                               ; failing if you've left your computer on for
  44. 56                               ; 6 months solid...
  45. 7R  CMP R1, #50                  ; If NOW is more than 50 csec since lasttime...
  46. 9P  STRGE R0, lasttime           ; then let the NULL through, and remember the
  47. :8  MOVGE R0, #0                 ; time as 'lasttime'.
  48. <L  MOVLT R0, #42                ; otherwise, change it into event type 42
  49. >1  LDR R1,  r1store             ; restore regs
  50.   LDR R2,  r2store
  51.   LDR R14, r14store
  52. B:  MOV PC, R14                  ; Return to the program
  53. taskid% = 0
  54.  "Wimp_Poll",1,b% 
  55.  17, 18:
  56.       
  57.  b%!16 
  58.         
  59. L!          
  60.  "Wimp_CloseDown"
  61.           
  62.         
  63.  &400C2:
  64. PK          
  65.  A task is starting up. If it isn't ME, then I'll attach the
  66. QH          
  67.  filter to it, and then quit. Much like the procedure for
  68. RH          
  69.  putting firecrackers in the neighbour's letterbox... ;-)
  70. T#          
  71.  b%!4 <> mytaskid% 
  72.             taskid% = b%!4
  73.             
  74.  Beep!
  75.           
  76.       
  77.  taskid% <> 0
  78.  Have found a task to slow, so register the filter for it, and then quit.
  79.  "OS_ReadMonotonicTime" 
  80.  !lasttime
  81.  "Filter_RegisterPostFilter", "SlowDown", filter, 0, taskid%, &FFFFFFFE
  82.  "Wimp_CloseDown", mytaskid%
  83.