home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / taskkill / !TaskKill / TKSrc105 < prev   
Encoding:
Text File  |  1995-03-18  |  10.1 KB  |  350 lines

  1. APP  : TaskKiller
  2. IN   : -
  3. OUT  : TaskKiller
  4. TYPE : Module
  5.  
  6. { Source code for Task Killer!
  7.   
  8.   Risc OS 3.11 :
  9.    Press Right-Alt-Break to kill the current task
  10.   Risc OS 3.00 :
  11.    Press Right-Alt-Scroll-lock to kill the current task
  12.   On either :
  13.    Press Right-Alt-Escape to generate error
  14.    Press Right-Alt-Keypad * to start a command prompt
  15.   
  16.   KILLING TASKS
  17.   =============
  18.   Use generate error first, this should exit most areas
  19.   Then if this doesn't work, killing should terminate the task
  20.   If you use either, then it is advised that you should reboot
  21.  
  22.                   ****** EXTREME WARNING *******
  23.       DO NOT USE THIS IF THE DESKTOP IS FUNCTIONING NORMALLY!
  24.         What will happen is that tasks will die randomly.
  25.         
  26.   COMMAND PROMPTS
  27.   ===============
  28.   This will bring up the standard * prompt from anywhere, except in the
  29.   desktop. Do not use any commands which may seriously affect the top level
  30.   application.
  31.   
  32.   DISCLAIMER
  33.   ==========
  34.   The author accepts no responsibility for this modules activities, and does
  35.   not guarentee its suitablity for any specific purpose. The module may not
  36.   be copied without this source code file.
  37.   
  38.   MAKING THIS CODE
  39.   ================
  40.   This code requires the !JFPatch pre-assembler to make the code. This is a
  41.   simple text-to-basic assembler which takes a text assembler file, makes a
  42.   basic program from it to assemble, assembles it and returns any errors.
  43.   Currently, it is under development and requires a lot of work before it
  44.   will be released in any form. As such, this file is mostly useless, but
  45.   must be distributed with the resultant module.
  46.   
  47. Contact                
  48. -------
  49. Any comments, queries, donations or bug reports can be sent to :
  50.  
  51. Fidonet NetMail :  Justin Fletcher at Arcade (0181 655 4412) [2:254/27]
  52. E-Mail : Gerph@arcade.demon.co.uk
  53.  
  54. Snail Mail :
  55.     Justin Fletcher
  56.     “Galadriel”
  57.     17b Cromwell Road,
  58.     Weeting,
  59.     Brandon,
  60.     Suffolk.
  61.     IP27 0QT
  62.  
  63. History
  64. -------
  65. Version 1.00 : Simple Alt-Escape function.
  66.                Written in BASIC.
  67. Version 1.02 : Converted to Patch code.
  68.                Added Alt-Break/Shift-Lock combination
  69.                Clears Escape disabled state
  70. Version 1.03 : Added Alt-Keypad * function
  71.                Release to Arcade.
  72. Version 1.04 : Added Conditional assembly of Wimp Command window
  73.                code.
  74.                Patch code coverted to Basic by JFPatch.
  75.                FiveStar Marketting release ?
  76. Version 1.05 : Corrected bugs caused by incorrect pathing of Basic file
  77. }
  78.  
  79. DEFINE MODULE
  80.   Name     : TaskKiller
  81.   Version  : 1.05
  82.   Date     : 18 Mar 1995
  83.   Author   : Justin Fletcher
  84.   Help     : TaskKiller
  85.   Init     : initcode%
  86.   Service  : srvcode%
  87.   Final    : finalcode%
  88.   Commands
  89.     Name   : TaskKiller
  90.     Help   : ...
  91.      The Task killer module will attempt to kill a task which has crashed. 
  92.      When a task stops responding, use these keys, in order of priority :|M
  93.       1. Use Right-Alt and Escape to exit using error handler|M
  94.       2. Use Right-Alt and {k2$} to kill the task with a machette!|M|M
  95.       WARNING : Do NOT use these in a correctly functioning desktop|M|M
  96.      The Task killer module can also be used to initiate a command prompt 
  97.      by Right-Alt-Keypad *.
  98.   End Commands
  99. END MODULE
  100.  
  101. PRE
  102.  DIM message_buffer% 256
  103.  *| Set Risc OS Version number
  104.  *Set RO$Version 311
  105.  *RmEnsure UtilityModule 3.11 Set RO$Version 300
  106.  *RmEnsure UtilityModule 3.00 Set RO$Version 200
  107.  riscos$=FNsystemvar("RO$Version")
  108.  REM These numbers count from top left of keyboard to bottom right
  109.  REM ie Esc = 0, f1=1, f2=2, f3=3, .. f12=12, Print=13, ScrLock=14
  110.  REM    Break =14, ~=15, 1=16, 2=17,
  111.  REM    TAB   = 38, LCtrl = 58, LShift= 75, Caps= 92
  112.  REM 
  113.  k1=&60:REM Right Alt key
  114.  IF riscos$="311" THENk2=&F :k2$="Break"
  115.  IF riscos$="300" THENk2=&E :k2$="Scroll-Lock"
  116.  k3=0  :REM Escape key
  117.  k4=36 :REM Keypad *
  118.  # COND INLINE
  119.  # COND enablewimp Do you want to assemble the wimp command prompt window
  120.  REM # COND SET enablewimp FALSE
  121. END PRE
  122.  
  123. .initcode%
  124.     STMFD   (sp)!,{link}
  125.     BL      doclaim
  126.     LDMFD   (sp)!,{pc}
  127. :
  128. .srvcode%
  129.     MOV     pc,link     ; ie return immediately
  130. ;    TEQ     R1,#&27    ; reset module
  131. ;    MOVNE   pc,link
  132. :
  133. .doclaim
  134.     STMFD   (sp)!,{R0-R2,link}
  135.     MOV     link,#0
  136.     STR     link,doingnow
  137.     STR     link,key1pressed
  138.     STR     link,key2pressed
  139.     STR     link,key3pressed
  140.     STR     link,key4pressed
  141.     MOV     R0,#&10               ; vector &10 ?
  142.     ADR     R1,newvector%         ; to be processed at newvector%
  143.     BL      claimvector%
  144.     MOV     R0,#&0E
  145.     MOV     R1,#&0B
  146.     SWI     "XOS_Byte"            ; enable keypress vector
  147.     MOV     R0,#0
  148.     STRB    R0,[R12,#8]
  149.     LDMFD   (sp)!,{R0-R2,pc}
  150.  
  151. .finalcode%
  152.     STMFD   (sp)!,{R0-R2,link}
  153.     MOV     R0,#&0D
  154.     MOV     R1,#&0B
  155.     SWI     "XOS_Byte"            ; disable keypress vector
  156.     LDR     R12,[R12,#0]
  157.     MOV     R0,#&10
  158.     ADR     R1,newvector%
  159.     BL      releasevector%
  160.     LDMFD   (sp)!,{R0-R2,pc}
  161.  
  162. .claimvector%
  163.     STMFD   (sp)!,{R2,link}
  164.     BL      releasevector%
  165.     MOV     R2,#0
  166.     SWI     "XOS_Claim"
  167.     LDMFD   (sp)!,{R2,pc}^
  168.  
  169. .releasevector%
  170.     STMFD   (sp)!,{R0-R2,link}
  171. .retryrelease%
  172.     LDMFD   sp,{R0,R1}
  173.     MOV     R2,#0
  174.     SWI     "XOS_Release"
  175.     BVC     retryrelease%
  176.     CMP     pc,#0
  177.     LDMFD   (sp)!,{R0-R2,pc}
  178.  
  179. .newvector%
  180.     CMP     R0,#&0B                ; is this a keypress ?
  181.     MOVNE   pc,link                 ; if not exit
  182.     STMFD   (sp)!,{R0-r2,R4,R5,link} ; stack regs
  183.     MOV     r4,#0
  184.     CMP     R2,#k1                 ; code for key 1 (controlling key)
  185.     STREQ   R1,key1pressed
  186.     MOVEQ   r4,#1
  187.     BEQ     whichkeys%
  188.     CMP     R2,#k2                 ; code for key 2 (Kill task)
  189.     STREQ   R1,key2pressed
  190.     MOVEQ   r4,#1
  191.     CMP     R2,#k3                 ; code for key 3 (Error)
  192.     STREQ   R1,key3pressed
  193.     MOVEQ   r4,#1
  194.     CMP     R2,#k4                 ; code for key 4 (OSCLI)
  195.     STREQ   R1,key4pressed
  196.     MOVEQ   r4,#1
  197.     CMP     r4,#1
  198.     LDMNEFD (sp)!,{R0-R2,R4,R5,pc}
  199. :
  200. .whichkeys%
  201.     LDR     R2,key1pressed
  202.     TEQ     R2,#0
  203.     LDMEQFD (sp)!,{R0-R2,R4,R5,pc}
  204.     LDR     R2,key2pressed
  205.     TEQ     R2,#0
  206.     BEQ     testforkey3
  207.     ADR     r1,doexitcode%         ; r1=address to jump to
  208. .setupjump
  209.     MOV     R5,pc
  210.     BIC     R4,R5,#1
  211.     TEQP    R4,#1
  212.     MOV     R0,R0
  213.     STMFD   (sp)!,{link}
  214.     LDRB    R0,doingnow
  215.     TEQ     R0,#0
  216.     BNE     alreadydoing
  217.     MOV     r0,r1                  ; r0=address
  218.     MOV     R1,#0
  219.     SWI     "XOS_AddCallBack"
  220.     MOVVC   R0,#1
  221.     STRVCB  R0,doingnow          ; if ok then set doing
  222. .alreadydoing
  223.     LDMFD   (sp)!,{link}
  224.     TEQP    R5,#0
  225.     MOV     R0,R0
  226.     LDMFD   (sp)!,{R0-R2,R4,R5,pc}
  227. .testforkey3                     ; check that key 3 is pressed (Error)
  228.     LDR     R2,key3pressed
  229.     TEQ     R2,#0
  230.     BEQ     testforkey4
  231.     ADR     r1,doerrorcode%
  232.     B       setupjump
  233. :
  234. .testforkey4                     ; check that key 4 is pressed (OSCLI)
  235.     LDR     R2,key4pressed
  236.     TEQ     R2,#0
  237.     LDMEQFD (sp)!,{R0-R2,R4,R5,pc}
  238.     ADR     r1,doosclicode%
  239.     B       setupjump
  240. :
  241. .doexitcode%
  242.     STMFD   (sp)!,{link}
  243.     MOV     R0,#0
  244.     STRB    R0,doingnow
  245.     BL      restorebreak
  246. ; code goes here -
  247. ;   SWI     "OS_EnterOS"
  248.     SWI     "OS_Exit"
  249. ; - to here
  250.     LDMFD   (sp)!,{pc}
  251. :
  252. .doerrorcode%
  253.     STMFD   (sp)!,{link}
  254.     MOV     R0,#0
  255.     STRB    R0,doingnow
  256.     BL      restorebreak
  257. ; code goes here -
  258.     ERR     "Program terminated"
  259. ; - to here
  260.     LDMFD   (sp)!,{pc}
  261. :
  262. :
  263. .doosclicode%
  264.     STMFD   (sp)!,{r0-r12,link}
  265.     BL      restorebreak
  266.     ADR     r0,wimpvar              ; address of wimp variable
  267.     ADR     r1,oscliline            ; address of buffer
  268.     MOV     r2,#255                 ; buffer length
  269.     MOV     r3,#0                   ; ?
  270.     MOV     r4,#3                   ; ?
  271.     SWI     "XOS_ReadVarVal"        ; read variable
  272.     BVS     exitoscli               ; exit if error
  273. ;     MOV     r0,r1
  274. ;     SWI     "OS_Write0"
  275.     LDR     r0,[r1,#0]              ; get first word
  276.     LDR     r2,commandstring        ; read what it should be for comm
  277.     CMP     r0,r2                   ; compare
  278.     LDRNE   r0,[r1,#0]              ; get second word
  279.     LDRNE   r2,commandstring+4      ; read what it should be for ands
  280.     CMPNE   r0,r2                   ; compare
  281.     BNE     wimprunning
  282. ; code goes here -
  283. .oscliloop
  284.     SWI     &100+ASC("*")
  285.     ADR     r0,oscliline        ; addr of buffer
  286.     MOV     r1,#&100            ; length of buffer
  287.     MOV     r2,#&20             ; min ascii accepted
  288.     MOV     r3,#&FF             ; max ascii accepted
  289.     SWI     "XOS_ReadLine"
  290.     BVS     osclierror          ; if error then process
  291.     CMP     r1,#0               ; if no characters typed then exit
  292.     BEQ     exitoscli
  293.     SWI     "XOS_CLI"           ; do command
  294.     BVC     oscliloop           ; if no error then loop around
  295. .osclierror
  296.     ADD     r0,r0,#4            ; skip error code byte
  297.     SWI     "OS_Write0"         ; write to screen
  298.     SWI     "OS_NewLine"
  299.     B       oscliloop
  300. .exitoscli
  301.     MOV     R0,#0
  302.     STRB    R0,doingnow
  303. ; - to here
  304.     LDMFD   (sp)!,{r0-r12,pc}^
  305. :
  306. .wimprunning
  307. # COND OF enablewimp
  308.     ADR     r0,wimpcommand
  309.     SWI     "Wimp_StartTask"
  310. # COND END
  311. { The above two commands will create a new task with the command GOS, and
  312.   therefore open a window in the middle of the desktop. This should 
  313.   not be used as on exit it tends to crash applications.
  314.   Feel free to re-enable it, but the author accepts no responsibility and
  315.   will not support bugs in this manner (unless you know a solution!) }
  316.     B       exitoscli
  317. :
  318. .restorebreak
  319.     STMFD   (sp)!,{link}
  320.     MOV     r0,#200
  321.     MOV     r1,#0
  322.     SWI     "OS_Byte"            ; Clear Break/Escape disabled
  323.     MOV     r0,#229
  324.     MOV     r1,#0
  325.     SWI     "OS_Byte"            ; Enable Escape
  326.     LDMFD   (sp)!,{pc}
  327. :
  328. ; variables
  329. .doingnow   :EQUD 0
  330. .key1pressed:EQUD 0
  331. .key2pressed:EQUD 0
  332. .key3pressed:EQUD 0
  333. .key4pressed:EQUD 0
  334. .oscliline
  335.     RES     256
  336. .wimpcommand:EQUS "GOS"+CHR$0:ALIGN
  337. .wimpvar    :EQUS "Wimp$State"+CHR$0:ALIGN
  338. .commandstring:EQUS "commands":ALIGN
  339.  
  340. # POST
  341. # RUN <CODE>
  342. # END of main code
  343. :
  344. REM FNsystemvar : Return the contents of any string system var
  345. DEFFNsystemvar(Var$):LOCAL addr
  346. SYS "XOS_ReadVarVal",Var$,message_buffer%,255,0,3TO,,len
  347. message_buffer%?len=13
  348. =$message_buffer%
  349.  
  350.