home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilst / wt_070 / Documents / Examples / 1st_Look / 020_WTserv (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1995-03-21  |  7.7 KB  |  155 lines

  1.     Name: 011_WTserv
  2.  Subject: The WTService handler.
  3.   Author: GUS
  4.  From now on:
  5.    the following FNs will be used:
  6.       FNhelp(<module name>$,<version>$,<help>$)  ; assembles module help
  7.       FNph(<string>$)    ; compresses and assembles a string to be displayed
  8.                          ; with SWI OS_PrettyPrint
  9.       FNid(<token>$)     ; returns the Id of a detokenised string
  10.    the following variables will be used:
  11.       module_title$      ; the name of the module
  12.       module_version$    ; module's version
  13.       module_filename$   ; the filename for the module
  14.       module_path$       ; the filepath for the filename
  15.       module_help$       ; module's help
  16.    the following mnemonics will be used:
  17.       '='   for 'equs' and 'equb'
  18.       'dcd' for 'equd'
  19. !module_title$   ="1stL_WTSer"
  20. module_version$ ="0.01"
  21. "module_filename$=module_title$
  22.  +module_path$    ="WTExamples:1st_Look."
  23. !4module_help$    ="Examining WTService hadler..."
  24.  code% 5*1024
  25.  p%=4 
  26. O%=code%
  27. [opt p%
  28. (F\__________________________________________________________ header
  29. .module_start%
  30. +?  dcd  (module_end%-module_start%) <<8 
  31.  module_header_end%
  32.   =    "WTmd"
  33.   dcd  module_help%
  34. /@  dcd  WTService_handler%      ; offset to WTService handler
  35. .module_header_end%
  36. 2D\__________________________________________________________ help
  37. .module_help%
  38. help(module_title$,module_version$,module_help$)
  39. 6Q\__________________________________________________________ WTService handler
  40. 8H; The manager sends various WTService messages to a WT module thru a
  41. 90; special handler named 'WTService handler'.
  42. :G; A module is informed by that about its status, the other modules,
  43. ;2; the memory needs, and for many other things.
  44. <J; The most usable WTService messages are those related with the module
  45. =3; state and three of them are demostrated here.
  46. ?S; The following 'entry' and 'exit' are not used only for the WTService handler,
  47. @P; are used for all other message handlers too (Service, Broadcast, Private).
  48. BH; On entry; R0, R2 - R8   are parameters and depend upon the message
  49. CR;           R1            is the message Id (message chunk and message number)
  50. DI;           R11           the low byte of message Id (message number)
  51. ER;           R12           pointer to module's default workspace (12byte block)
  52. F/;           R13           SVC stack pointer
  53. G,;           R14           return address
  54. H&;           prossesor in  SVC mode
  55. J.; On exit;  R13           always preserved
  56. K5;           R9 - R12, R14 can always be corrupted
  57. ;           V flag clear
  58. N1;           R1 = 0        the message claimed
  59. O5;           R0, R2 - R8   depend upon the message
  60. PO;                         (!!! Preserved If Not Needed For The Message !!!)
  61. ;           V flag clear
  62. S(;           R0 - R8       preserved,
  63. T<;                            because the message ignored
  64. UF;                         or because the message cannot be claimed
  65. VK;                         or because we don't need to claim the message
  66. X3;           V flag set    (the message smashed)
  67. Y4;           R0            pointer to error block
  68. Z5;           R1 - R8       depend upon the message
  69. [O;                         (!!! Preserved If Not Needed For The Message !!!)
  70. .WTService_handler%
  71. _R  teq     1,#
  72. id("WTService_Initialisation") ; is the message initialisation ?
  73.   beq     initialise
  74. aP  teq     1,#
  75. id("WTService_Finalisation")   ; is the message finalisation ?
  76.   beq     finalisation
  77. cO  teq     1,#
  78. id("WTService_Enter")          ; is the message enter (run) ?
  79.   movnes  15,14
  80. e8.enter                               ; enter code...
  81. fN                                     ; The enter message is send after all
  82. gS                                     ; initialise messages when the module run,
  83. hO                                     ; and when module is about to start as
  84. i7                                     ; a Wimp task.
  85. jI  adr     0,run_code                 ; return the address of run code
  86. k<  mov     1,#0                       ; claim the message
  87. lT  movs    15,14                      ; return to the manager which will make the
  88. mM                                     ; module Current Active Object (CAO)
  89. nF                                     ; and will call the run code.
  90. pP.run_code                            ; This code is called in User mode with
  91. qT                                     ; R12 pointer to default module's workspace
  92. rN                                     ; and R0 pointer to parameter string.
  93. sI                                     ; You can start a wimp task here
  94. tD                                     ; just like system modules.
  95. vF  teq     0,#0                       ; Is the a parameter string ?
  96. wA  swine   "OS_Write0"                ;   if there is print it
  97. x<  swine   "OS_NewLine"               ;   and change line
  98. y;  swi     "OS_WriteS"                ; display a string
  99. z%          ="Just run!":=10:=13:=0
  100. {P  swi     "OS_Exit"                  ; The module is the CAO, so use OS_Exit
  101. |A                                     ; or SWI "WT_ExitAndDie"
  102. }C                                     ; e.g. when you are a task
  103. N.initialise                          ; The module is about to be installed
  104. L                                     ; all other modules agree (or don't
  105. N                                     ; care) about that, so the module can
  106. R                                     ; try to initilised by getting workspace,
  107. T                                     ; claiming vectors, registering WT modules,
  108. .                                     ; etc
  109. M                                     ; If initialisation fails, smash the
  110. O                                     ; message by returning with R0 pointer
  111. I                                     ; to error block and V flag set.
  112.   stmfd   13!,{2,3,14}
  113. ;  mov     0,#6                       ; get an RMA block
  114. *  mov     3,#64                      ;
  115. *  swi     "XOS_Module"               ;
  116. M  strvc   2,[12]                     ; store pointer to first word of the
  117. L                                     ; default 12byte module's workspace
  118. ;  adrvc   0,hello                    ; display a string
  119. *  swivc   "XOS_Write0"               ;
  120.   ldmfd   13!,{2,3,15}
  121. .hello
  122.    ="Hello world!":=10:=13:=0
  123. C.finalisation                        ; The module has to die...
  124. R                                     ; Release any vector, free workspace etc.
  125. Q                                     ; You don't have to free an RMA block if
  126. O                                     ; its pointer is stored in 1st word of
  127. F                                     ; default module's workspace.
  128. P                                     ; If you cannot die, smash the message.
  129.   stmfd   13!,{14}
  130.   adr     0,bye
  131.   swi     "XOS_Write0"
  132.   ldmfd   13!,{15}
  133.   ="Bye-bye...":=10:=13:=0
  134. J\__________________________________________________________ module end
  135. .module_end%
  136. I\____________________________________________________________________
  137.  Install a WT module from memory
  138. "WT_Install",code%
  139. "OS_File",10,module_path$+module_filename$,&b6f,,code%,O%
  140. I_____________________________________________________________________
  141. help(ttl$,version$,hlp$)
  142. hlp$<>"" hlp$=
  143. 13+hlp$
  144.  ttl$<8 ttl$+=
  145. [optp%:=ttl$:=9:=version$
  146. :=" ("+
  147. $,5,11)+") by GUS, for 1st_Look on WT modules"
  148. ph(hlp$):=0:align:]:=0
  149. ph(ps$):
  150. "WT_CallDLRD",p%,"PH_Compress",P%,O%,ps$ 
  151. ,,P%,O%:=0
  152. id(s$):
  153. "WT_Tokenise",,s$ 
  154. ,t%:=t%
  155.