home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1995-03-21 | 7.7 KB | 155 lines |
- Name: 011_WTserv
- Subject: The WTService handler.
- Author: GUS
- From now on:
- the following FNs will be used:
- FNhelp(<module name>$,<version>$,<help>$) ; assembles module help
- FNph(<string>$) ; compresses and assembles a string to be displayed
- ; with SWI OS_PrettyPrint
- FNid(<token>$) ; returns the Id of a detokenised string
- the following variables will be used:
- module_title$ ; the name of the module
- module_version$ ; module's version
- module_filename$ ; the filename for the module
- module_path$ ; the filepath for the filename
- module_help$ ; module's help
- the following mnemonics will be used:
- '=' for 'equs' and 'equb'
- 'dcd' for 'equd'
- !module_title$ ="1stL_WTSer"
- module_version$ ="0.01"
- "module_filename$=module_title$
- +module_path$ ="WTExamples:1st_Look."
- !4module_help$ ="Examining WTService hadler..."
- code% 5*1024
- p%=4
- O%=code%
- [opt p%
- (F\__________________________________________________________ header
- .module_start%
- +? dcd (module_end%-module_start%) <<8
- module_header_end%
- = "WTmd"
- dcd module_help%
- /@ dcd WTService_handler% ; offset to WTService handler
- .module_header_end%
- 2D\__________________________________________________________ help
- .module_help%
- help(module_title$,module_version$,module_help$)
- 6Q\__________________________________________________________ WTService handler
- 8H; The manager sends various WTService messages to a WT module thru a
- 90; special handler named 'WTService handler'.
- :G; A module is informed by that about its status, the other modules,
- ;2; the memory needs, and for many other things.
- <J; The most usable WTService messages are those related with the module
- =3; state and three of them are demostrated here.
- ?S; The following 'entry' and 'exit' are not used only for the WTService handler,
- @P; are used for all other message handlers too (Service, Broadcast, Private).
- BH; On entry; R0, R2 - R8 are parameters and depend upon the message
- CR; R1 is the message Id (message chunk and message number)
- DI; R11 the low byte of message Id (message number)
- ER; R12 pointer to module's default workspace (12byte block)
- F/; R13 SVC stack pointer
- G,; R14 return address
- H&; prossesor in SVC mode
- J.; On exit; R13 always preserved
- K5; R9 - R12, R14 can always be corrupted
- ; V flag clear
- N1; R1 = 0 the message claimed
- O5; R0, R2 - R8 depend upon the message
- PO; (!!! Preserved If Not Needed For The Message !!!)
- ; V flag clear
- S(; R0 - R8 preserved,
- T<; because the message ignored
- UF; or because the message cannot be claimed
- VK; or because we don't need to claim the message
- X3; V flag set (the message smashed)
- Y4; R0 pointer to error block
- Z5; R1 - R8 depend upon the message
- [O; (!!! Preserved If Not Needed For The Message !!!)
- .WTService_handler%
- _R teq 1,#
- id("WTService_Initialisation") ; is the message initialisation ?
- beq initialise
- aP teq 1,#
- id("WTService_Finalisation") ; is the message finalisation ?
- beq finalisation
- cO teq 1,#
- id("WTService_Enter") ; is the message enter (run) ?
- movnes 15,14
- e8.enter ; enter code...
- fN ; The enter message is send after all
- gS ; initialise messages when the module run,
- hO ; and when module is about to start as
- i7 ; a Wimp task.
- jI adr 0,run_code ; return the address of run code
- k< mov 1,#0 ; claim the message
- lT movs 15,14 ; return to the manager which will make the
- mM ; module Current Active Object (CAO)
- nF ; and will call the run code.
- pP.run_code ; This code is called in User mode with
- qT ; R12 pointer to default module's workspace
- rN ; and R0 pointer to parameter string.
- sI ; You can start a wimp task here
- tD ; just like system modules.
- vF teq 0,#0 ; Is the a parameter string ?
- wA swine "OS_Write0" ; if there is print it
- x< swine "OS_NewLine" ; and change line
- y; swi "OS_WriteS" ; display a string
- z% ="Just run!":=10:=13:=0
- {P swi "OS_Exit" ; The module is the CAO, so use OS_Exit
- |A ; or SWI "WT_ExitAndDie"
- }C ; e.g. when you are a task
- N.initialise ; The module is about to be installed
- L ; all other modules agree (or don't
- N ; care) about that, so the module can
- R ; try to initilised by getting workspace,
- T ; claiming vectors, registering WT modules,
- . ; etc
- M ; If initialisation fails, smash the
- O ; message by returning with R0 pointer
- I ; to error block and V flag set.
- stmfd 13!,{2,3,14}
- ; mov 0,#6 ; get an RMA block
- * mov 3,#64 ;
- * swi "XOS_Module" ;
- M strvc 2,[12] ; store pointer to first word of the
- L ; default 12byte module's workspace
- ; adrvc 0,hello ; display a string
- * swivc "XOS_Write0" ;
- ldmfd 13!,{2,3,15}
- .hello
- ="Hello world!":=10:=13:=0
- C.finalisation ; The module has to die...
- R ; Release any vector, free workspace etc.
- Q ; You don't have to free an RMA block if
- O ; its pointer is stored in 1st word of
- F ; default module's workspace.
- P ; If you cannot die, smash the message.
- stmfd 13!,{14}
- adr 0,bye
- swi "XOS_Write0"
- ldmfd 13!,{15}
- ="Bye-bye...":=10:=13:=0
- J\__________________________________________________________ module end
- .module_end%
- I\____________________________________________________________________
- Install a WT module from memory
- "WT_Install",code%
- "OS_File",10,module_path$+module_filename$,&b6f,,code%,O%
- I_____________________________________________________________________
- help(ttl$,version$,hlp$)
- hlp$<>"" hlp$=
- 13+hlp$
- ttl$<8 ttl$+=
- [optp%:=ttl$:=9:=version$
- :=" ("+
- $,5,11)+") by GUS, for 1st_Look on WT modules"
- ph(hlp$):=0:align:]:=0
- ph(ps$):
- "WT_CallDLRD",p%,"PH_Compress",P%,O%,ps$
- ,,P%,O%:=0
- id(s$):
- "WT_Tokenise",,s$
- ,t%:=t%
-