home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1993-02-21 | 3.1 KB | 83 lines |
- >SlowFilter
- By Jason Williams 1993
- Experimental program to filter out some NULL events from a
- given task. Currently set to permanently do this for one app, and
- allows a MAXIMUM of 1 NULL every half second to get through.
- Undelivered NULLs are converted into events of type 42 (hack)
- No attempt has been made to make this code efficient.
- Usage: Run this program, and then launch another application
- (e.g. Draw), and then try doing anything that sits on NULLs
- (e.g. draw a set of lines - notice how drag updates happen only
- at half-second intervals?)
- Notice that other operations (e.g. typing in some text) are
- totally unaffected.
- This thus demonstrates how a backgrounded task can be slowed to
- allow other applications to get more CPU time.
- Run this program at your own risk. (It runs fine on my machine though)
- b% 256
- $b%="TASK"
- "Wimp_Initialise", 200, !b%, "SlowDown Init"
- ,mytaskid%
- Assemble a bit of code into the RMA (must be permanently paged in)
- "OS_Module",6,,,100
- ,,code%;flags%
- code%<1
- flags%<>6
- 42 "Not enough room in RMA":
- P%=code%
- [ OPT 0
- .lasttime:EQUD 0
- .r1store: EQUD 0
- .r2store: EQUD 0
- .r14store:EQUD 0
- ALIGN
- .filter
- *Q CMP R0, #0 ; Is this a NULL event? Let all others through
- +J MOVNE PC, R14 ; (this could un-sleep an application?)
- -E STR R1, r1store ; Save regs which we must preserve
- STR R2, r2store
- STR R14, r14store
- 1 SWI "OS_ReadMonotonicTime"
- LDR R1, lasttime
- 3S SUB R1, R0, R1 ; Yeah, I know, a 1 in 10 billion chance of this
- 4P ; failing if you've left your computer on for
- 56 ; 6 months solid...
- 7R CMP R1, #50 ; If NOW is more than 50 csec since lasttime...
- 9P STRGE R0, lasttime ; then let the NULL through, and remember the
- :8 MOVGE R0, #0 ; time as 'lasttime'.
- <L MOVLT R0, #42 ; otherwise, change it into event type 42
- >1 LDR R1, r1store ; restore regs
- LDR R2, r2store
- LDR R14, r14store
- B: MOV PC, R14 ; Return to the program
- taskid% = 0
- "Wimp_Poll",1,b%
- 17, 18:
-
- b%!16
-
- L!
- "Wimp_CloseDown"
-
-
- &400C2:
- PK
- A task is starting up. If it isn't ME, then I'll attach the
- QH
- filter to it, and then quit. Much like the procedure for
- RH
- putting firecrackers in the neighbour's letterbox... ;-)
- T#
- b%!4 <> mytaskid%
- taskid% = b%!4
-
- Beep!
-
-
- taskid% <> 0
- Have found a task to slow, so register the filter for it, and then quit.
- "OS_ReadMonotonicTime"
- !lasttime
- "Filter_RegisterPostFilter", "SlowDown", filter, 0, taskid%, &FFFFFFFE
- "Wimp_CloseDown", mytaskid%
-