home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / deskutils / _a_l / boota / C-source / s / BootAutil
Encoding:
Text File  |  1991-12-18  |  15.8 KB  |  363 lines

  1.           TTL      BootAutil - send message to BootA
  2.  
  3. ;*===================================================================*
  4. ;*                                                                   *
  5. ;*  BootAutil  -  send message to BootA                              *
  6. ;*  ---------                                                        *
  7. ;*                                                                   *
  8. ;*                Version 1.00                                       *
  9. ;*                Paul Witheridge  -  15 December 1991               *
  10. ;*                                                                   *
  11. ;*                                                                   *
  12. ;*  This application sends a message to BootA to request one of the  *
  13. ;*  following actions:                                               *
  14. ;*                                                                   *
  15. ;*                                                                   *
  16. ;*  (1) A client application's icon be replaced by a different       *
  17. ;*      sprite:                                                      *
  18. ;*                                                                   *
  19. ;*      e.g. *BootAutil -sprite newname                              *
  20. ;*                                                                   *
  21. ;*  (2) A client application's icon be removed (equivalent to 'quit' *
  22. ;*      on the BootA client menu:                                    *
  23. ;*                                                                   *
  24. ;*      e.g. *BootAutil -quit                                        *
  25. ;*                                                                   *
  26. ;*  The client application is identified by is icon handle which     *
  27. ;*  BootA stores in the system variable 'BootA$Handle' before it     *
  28. ;*  runs the client application. Alternatively, the client's icon    *
  29. ;*  handle can be specified on the command line:                     *
  30. ;*                                                                   *
  31. ;*      e.g. *BootAutil -sprite newname -handle <myvar>              *
  32. ;*           *BootAutil -quit -handle <myvar>                        *
  33. ;*                                                                   *
  34. ;*  but since the icon handle is an internal code, this would only   *
  35. ;*  be useful where the client application had copied BootA$Handle   *
  36. ;*  into its own system variable in order to preserve it.            *
  37. ;*                                                                   *
  38. ;*  Note that any sprite replacing the original sprite installed on  *
  39. ;*  the icon bar for a client application should be no larger than   *
  40. ;*  that original sprite.                                            *
  41. ;*                                                                   *
  42. ;*  The command to run BootAutil should be incorporated in the       *
  43. ;*  !RunA obey file for the client application. Since BootAutil is   *
  44. ;*  technically an application and uses the application work area,   *
  45. ;*  issuing directly from the client application will result in the  *
  46. ;*  client application being overlaid.                               *
  47. ;*                                                                   *
  48. ;*-------------------------------------------------------------------*
  49. ;*                                                                   *
  50. ;*  COPYRIGHT NOTICE                                                 *
  51. ;*                                                                   *
  52. ;*  BootAutil is subject to Copyright.                               *
  53. ;*                                                                   *
  54. ;*  Permission is granted by the author to any recipient of this     *
  55. ;*  material to use and make/disseminate copies of the application   *
  56. ;*  provided that no charges are made for doing so (other than to    *
  57. ;*  cover any cost of media or postage) and that this notice is      *
  58. ;*  included with all copies.                                        *
  59. ;*                                                                   *
  60. ;*===================================================================*
  61.  
  62. ;*-------------------------------------------------------------------*
  63. ;* Define symbolic registers                                         *
  64. ;*-------------------------------------------------------------------*
  65.  
  66. r0        RN       0
  67. r1        RN       1
  68. r2        RN       2
  69. r3        RN       3
  70. r4        RN       4
  71. r5        RN       5
  72. r6        RN       6
  73. r7        RN       7
  74. r8        RN       8
  75. r9        RN       9
  76. r10       RN       10
  77. r11       RN       11
  78. r12       RN       12
  79. r13       RN       13
  80. r14       RN       14
  81. r15       RN       15
  82. pc        RN       15
  83.  
  84. ;*-------------------------------------------------------------------*
  85. ;* Define symbolic SWI numbers                                       *
  86. ;*-------------------------------------------------------------------*
  87.  
  88. bit_17                 EQU  1 << 17
  89.  
  90. OS_WriteC              EQU  &00
  91. XOS_WriteC             EQU  bit_17 + OS_WriteC
  92.  
  93. OS_WriteI              EQU  &100
  94. XOS_WriteI             EQU  bit_17 + OS_WriteI
  95.  
  96. OS_WriteS              EQU  &01
  97. XOS_WriteS             EQU  bit_17 + OS_WriteS
  98.  
  99. OS_Write0              EQU  &02
  100. XOS_Write0             EQU  bit_17 + OS_Write0
  101.  
  102. OS_NewLine             EQU  &03
  103. XOS_NewLine            EQU  bit_17 + OS_NewLine
  104.  
  105. OS_Byte                EQU  &06
  106. XOS_Byte               EQU  bit_17 + OS_Byte
  107.  
  108. OS_GetEnv              EQU  &10
  109. XOS_GetEnv             EQU  bit_17 + OS_GetEnv
  110.  
  111. OS_Exit                EQU  &11
  112.  
  113. OS_EvaluateExpression  EQU  &2D
  114. XOS_EvaluateExpression EQU  bit_17 + OS_EvaluateExpression
  115.  
  116. OS_ReadArgs            EQU  &49
  117. XOS_ReadArgs           EQU  bit_17 + OS_ReadArgs
  118.  
  119. Wimp_Initialise        EQU  &400C0
  120. XWimp_Initialise       EQU  bit_17 + Wimp_Initialise
  121.  
  122. Wimp_Poll              EQU  &400C7
  123. XWimp_Poll             EQU  bit_17 + Wimp_Poll
  124.  
  125. Wimp_CloseDown         EQU  &400DD
  126. XWimp_CloseDown        EQU  bit_17 + Wimp_CloseDown
  127.  
  128. Wimp_ReportError       EQU  &400DF
  129. XWimp_ReportError      EQU  bit_17 + Wimp_ReportError
  130.  
  131. Wimp_SendMessage       EQU  &400E7
  132. XWimp_SendMessage      EQU  bit_17 + Wimp_SendMessage
  133.  
  134. ;*-------------------------------------------------------------------*
  135. ;* Define Wimp_Poll reason codes                                     *
  136. ;*-------------------------------------------------------------------*
  137.  
  138. Null_Reason_Code          EQU   0
  139. ReDraw_Window_Request     EQU   1
  140. Open_Window_Request       EQU   2
  141. Close_Window_Request      EQU   3
  142. Pointer_Leaving_Window    EQU   4
  143. Pointer_Entering_Window   EQU   5
  144. Mouse_Click               EQU   6
  145. User_Drag_Box             EQU   7
  146. Key_Pressed               EQU   8
  147. Menu_Selection            EQU   9
  148. Scroll_Request            EQU  10
  149. Lose_Caret                EQU  11
  150. Gain_Caret                EQU  12
  151. User_Message              EQU  17
  152. User_Message_Recorded     EQU  18
  153. User_Message_Acknowledge  EQU  19
  154.  
  155. ;*-------------------------------------------------------------------*
  156. ;* Define layout of work area (follows end of assembled program)     *
  157. ;*-------------------------------------------------------------------*
  158.  
  159.           ^        0,r12
  160. wrkthndl  #        4                    ; Wimp task handle
  161. wrkbforg  #        0                    ; Start of buffer for ReadArgs
  162. wrkbfrun  #        4                    ; Pointer to *RUN
  163. wrkbffil  #        4                    ; Pointer to file name
  164. wrkbfqut  #        4                    ; Switch for -quit argument
  165. wrkbfspr  #        4                    ; Pointer to -sprite argument
  166. wrkbfhdl  #        4                    ; Pointer to -handle argument
  167. wrkbftxt  #        80                   ; Argument output area
  168. wrkbfend  #        0                    ; End of ReadArgs buffer
  169. wrkbfsiz  EQU      wrkbfend - wrkbforg  ; Length of ReadArgs buffer
  170. wrkmsorg  #        0                    ; Start of wimp message block.
  171. wrkmslen  #        4                    ; Block length
  172. wrkmstsk  #        4                    ; Task handle (not used)
  173. wrkmsyrf  #        4                    ; Your ref (not used)
  174. wrkmsmrf  #        4                    ; My ref (set to zero)
  175. wrkmsact  #        4                    ; Message action code
  176. wrkmshdl  #        4                    ; Icon handle stored here
  177. wrkmsspr  #        16                   ; Sprite name stored here
  178. wrkmsend  #        0                    ; End of message block.
  179. wrkmssiz  EQU      wrkmsend - wrkmsorg  ; Length of message block.
  180.  
  181. ;*-------------------------------------------------------------------*
  182. ;* Entry from caller. Establish addressability to data areas         *
  183. ;*-------------------------------------------------------------------*
  184.  
  185. util      BL      database              ; Go set up reg.11 --> data
  186.                                         ;           reg.12 --> work
  187.  
  188. ;*-------------------------------------------------------------------*
  189. ;* Get address of command string and set up stack pointer.           *
  190. ;*-------------------------------------------------------------------*
  191.  
  192.           SWI     XOS_GetEnv            ; Get address of command string
  193.           BVS     errexit               ; Go exit if error occurred.
  194.  
  195.           MOV     r13,r1                ; Set up stack.
  196.  
  197. ;*-------------------------------------------------------------------*
  198. ;* Use ReadArgs to analyse command line                              *
  199. ;*-------------------------------------------------------------------*
  200.  
  201.           ADR     r2,wrkbforg           ; Invoke OS_ReadArgs to parse
  202.           MOV     r1,r0                 ; command line (pointed to by
  203.           ADD     r0,r11,#keydefn       ; reg.0 on return from GetEnv).
  204.           MOV     r3,#wrkbfsiz
  205.           SWI     XOS_ReadArgs
  206.           BVS     errexit               ; Go exit if error.
  207.  
  208. ;*-------------------------------------------------------------------*
  209. ;* Check either "-quit" or "-sprite" but not both specified          *
  210. ;*-------------------------------------------------------------------*
  211.  
  212.           LDR     r2,wrkbfqut           ; Set reg.2 to zero if '-quit'
  213.           MOVS    r2,r2                 ; not specified, or to one if
  214.           MOVNE   r2,#1                 ; it is specified. Do likewise
  215.           LDR     r3,wrkbfspr           ; for reg.3 and '-sprite'. Use
  216.           MOVS    r3,r3                 ; exclusive OR to test if both
  217.           MOVNE   r3,#1                 ; or neither specified.
  218.           EORS    r0,r2,r3
  219.  
  220.           ADDEQ   r0,r11,#badparm       ; If so exit with error
  221.           BEQ     errexit               ; message.
  222.  
  223. ;*-------------------------------------------------------------------*
  224. ;* Obtain BootA handle from parameters or system variable            *
  225. ;*-------------------------------------------------------------------*
  226.  
  227.           LDR     r0,wrkbfhdl           ; Check if '-handle' argument
  228.           MOVS    r0,r0                 ; specified. If not, use default
  229.           ADDEQ   r0,r11,#varname       ; value of <BootA$Handle>.
  230.  
  231.           ADR     r1,wrkmsorg           ; Handle should be integer.
  232.           MOV     r2,#16
  233.           SWI     XOS_EvaluateExpression
  234.           BVS     errexit
  235.           MOVS    r1,r1                 ; Evaluate. Take error exit
  236.           ADDNE   r0,r11,#badhndl       ; if not integer.
  237.           BNE     errexit
  238.  
  239.           STR     r2,wrkmshdl           ; Else save handle value.
  240.  
  241. ;*-------------------------------------------------------------------*
  242. ;* Sign on to Wimp manager so we can send a message to BootA.        *
  243. ;*-------------------------------------------------------------------*
  244.  
  245.           MOV     r0,#200               ; Register as task so that
  246.           LDR     r1,task               ; we can send  message to
  247.           ADD     r2,r11,#taskid        ; BootA and then check that
  248.           SWI     XWimp_Initialise      ; it was actually received.
  249.           BVS     errexit
  250.           STR     r1,wrkthndl
  251.  
  252. ;*-------------------------------------------------------------------*
  253. ;* Initialise message block                                          *
  254. ;*-------------------------------------------------------------------*
  255.  
  256.           MOV     r0,#wrkmssiz          ; Block length
  257.           STR     r0,wrkmslen
  258.           MOV     r0,#0                 ; Your ref (0 for original msg)
  259.           STR     r0,wrkmsyrf
  260.           LDR     r9,msgactn            ; Action code &211172 for
  261.           LDR     r1,wrkbfspr           ; sprite name change or &211173
  262.           MOVS    r1,r1                 ; for quit request.
  263.           ADDEQ   r9,r9,#1
  264.           STR     r9,wrkmsact           ; Reg.9 = action code
  265.           BEQ     util0020
  266.           LDRB    r3,[r1],#2            ; New sprite name if request
  267.           ADR     r2,wrkmsspr           ; to change sprite.
  268.           MOVS    r3,r3
  269. util0010  LDRPLB  r0,[r1],#1
  270.           STRPLB  r0,[r2],#1
  271.           SUBPLS  r3,r3,#1
  272.           BPL     util0010
  273.           STRB    r3,[r2],#1
  274.  
  275. ;*-------------------------------------------------------------------*
  276. ;* Send message to creator of sprite (i.e. BootA)                    *
  277. ;*-------------------------------------------------------------------*
  278.  
  279. util0020  MOV     r0,#User_Message      ; Use reason code 17.
  280.           ADR     r1,wrkmsorg
  281.           MOV     r2,#-2                ; Addressee is creator of
  282.           LDR     r3,wrkmshdl           ; sprite on icon bar.
  283.           SWI     XWimp_SendMessage
  284.           BVC     util0030
  285.  
  286.           ADD     r2,r11,#taskid        ; If send failed report
  287.           MOV     r1,#0                 ; error message.
  288.           SWI     XWimp_ReportError
  289.  
  290. ;*-------------------------------------------------------------------*
  291. ;* Perform Wimp Poll to let BootA do its stuff                       *
  292. ;*-------------------------------------------------------------------*
  293.  
  294. util0030  LDR     r0,pollmask           ; Perform Wimp Poll loop until
  295.           ADR     r1,wrkmsorg           ; reason code 0 is returned.
  296.           SWI     XWimp_Poll
  297.           BVS     util0040
  298.           TEQ     r0,#0
  299.           BNE     util0030
  300.  
  301. ;*-------------------------------------------------------------------*
  302. ;* Sign off from Wimp manager and exit.                              *
  303. ;*-------------------------------------------------------------------*
  304.  
  305. util0040  LDR     r0,wrkthndl           ; Use our task handle
  306.           LDR     r1,task               ; specifically just in case.
  307.           SWI     XWimp_CloseDown
  308.           BVS     errexit
  309.  
  310.           MOV     r2,#0                 ; Exit and set zero
  311. util0050  LDR     r1,abex               ; return code.
  312.           MOV     r0,#0
  313.           SWI     OS_Exit
  314.  
  315. ;*-------------------------------------------------------------------*
  316. ;* Issue error message and exit (reg.0 points to error block)        *
  317. ;*-------------------------------------------------------------------*
  318.  
  319. errexit   ADD     r2,r11,#taskid        ; Use Wimp_ReportError to
  320.           MOV     r1,#0                 ; issue error message.
  321.           SWI     XWimp_ReportError
  322.           MOV     r2,#4
  323.           B       util0050
  324.  
  325. ;*-------------------------------------------------------------------*
  326. ;* Data areas                                                        *
  327. ;*-------------------------------------------------------------------*
  328.  
  329. task      DCB     "TASK"
  330. abex      DCB     "ABEX"
  331. msgactn   DCD     &211172                 ; Message action code.
  332. pollmask  DCD     2_11100001100101110010
  333.  
  334. database  ADR     r11,dataorg             ; Establish reg.11 as base
  335.           ADR     r12,wrkarea             ; register for data and
  336.           MOV     pc,r14                  ; reg.12 for work area.
  337. dataorg
  338.  
  339.           ALIGN
  340. badparm   *       . - dataorg
  341.           DCD     0
  342.           DCB     "either '-quit' or '-sprite' parameter "
  343.           DCB     "required (but not both)",0
  344.  
  345.           ALIGN
  346. badhndl   *       . - dataorg
  347.           DCD     0
  348.           DCB     "bad handle"
  349.  
  350. taskid    *       . - dataorg
  351.           DCB     "BootAutil",0
  352.  
  353. keydefn   *       . - dataorg
  354.           DCB     ",,quit/S,sprite/K/G,handle/K",0
  355.  
  356. varname   *       . - dataorg
  357.           DCB     "<BootA$Handle>",0
  358.  
  359.           ALIGN
  360. wrkarea
  361.  
  362.           END
  363.