home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / utilities / zap / !Zap / Docs / E-Command < prev    next >
Encoding:
Text File  |  1994-02-20  |  14.0 KB  |  310 lines

  1. *************************************************************************
  2. * >E-Command    Documents how to add commands to Zap            *
  3. *************************************************************************
  4.  
  5. As mentioned in the ReadMe file, commands are added to Zap by registering a
  6. table of commands when the module providing the extra commands initialises.
  7. You should use the call Zap_AddCommands to register the table. The table has
  8. the format below. All offsets are from your module start unless otherwise
  9. indicated.
  10.  
  11.     #0    Offset of table from start of module (so Zap can convert the
  12.         offsets below into addresses).
  13.     #4    Offset from module start of 'Zap service call code' or 0
  14.         if none. Zap calls this entry point to tell you about
  15.         various things - see the section below.
  16.     #8    List of commands, terminated by a zero word. Each element
  17.         of the list has the format:
  18.         
  19.         <command name>+<0 byte terminator>+
  20.         <ZERO bytes padding until word aligned>+
  21.         <word giving command offset from module start>
  22.         
  23. The command name must be in UPPER CASE in this table. In general, command
  24. names are not case sensitive, but they are converted to upper case in order
  25. to search for them in the command tables. The characters padding to the next
  26. word alignment MUST be ZEROs as the table is searched through in words not
  27. in bytes.
  28.  
  29. When a command is found in the table, its address is calculated, and
  30. henceforth the command is referred to by its address. This unfortunately
  31. means that I cannot pass the command your module workspace when the command
  32. is called as I do not know which module the command lies in. This is not
  33. usually a problem however as you may claim workspace from Zap's heap. If this
  34. is not sufficient, then you will just have to store the address of your
  35. workspace in the module itself and read it when you are called (until I work
  36. out a better method).
  37.  
  38. The address of the command is of course the address called when the command
  39. is executed. However, at offset -4, the word before the first instruction of
  40. the command, some flags are stored. These flags determine what type of
  41. parameter the command takes and how the command interacts with the
  42. minibuffer. This word must be filled in. It's meaning is as follows:
  43.  
  44. b0        Set if the command doesn't need R10 on entry (eg called from
  45. b1        Set if the command doesn't need R8 on entry   a menu).
  46. b2        Set if the command doesn't need R9 on entry
  47. b3-b5        Argument type for the command:
  48.         0 = Command takes no parameters
  49.         1 = Command takes a list of bytes as parameter
  50.         2 = Command takes a list of words as parameter
  51.         3 = Command takes a string as parameter
  52.         4 = Command takes a block of data as parameter
  53.         5-7 reserved
  54. b6        Set if you wished to be called before minibuffer opened
  55. b7        Set if you wish to be called after every minibuffer update
  56. b8        Set if you wish to be called before a key is inserted into
  57.         the minibuffer (and possibly alter it).
  58. b9        Set if you want TAB to complete file names in the minibuffer
  59. b10        Set if you may want to kill the minibuffer when it starts up.
  60. b11        Set if you may want minibuffer to remain open when command
  61.         has finished.
  62. b12        Set if you wish universal argument to multiply R1 by n on
  63.         calling the instruction instead of calling it n times.
  64.         If the command takes byte or word list data then the data
  65.         is duplicated the given number of times.
  66. b13        Reserved for Paul Moore's system.
  67. b14        Set if the command should not be executed when loading a
  68.         file to prevent Trojans.
  69. b15-b31        Reserved - set to 0
  70.  
  71. Bits 0-2 are used by commands which may be called from a menu, and thus may
  72. not be typed. You should leave them as 0.
  73.  
  74. The entry/exit conditions of your command depend on your flags word as I will
  75. detail below. You are ALWAYS called with the following registers set up on
  76. entry:
  77.  
  78.     R3 = info flags:
  79.         b0 Set => The last command call was to this command as well.
  80.             (eg to spot cumulative ctrl K's/Yanks).
  81.         b1-b27 => Reserved
  82.         b28-b31=> Top bits of R2 when command called via
  83.               Zap_ProcessCommand.
  84.     R8 = window of the input caret (see E-Windows) (unless flags b1 set)
  85.     R9 = file block associated with R8 (see E-File) (flags b2=0)
  86.     R10 = cursor block pointer of input cursor (see E-Cursors) (b3=0)
  87.           (This is car_cursor if the cursors are combined and
  88.            car_input if they are split - see E-Vars).
  89.     R13 = small FD stack
  90.     
  91. And in general registers R0-R2 have the meaning:
  92.  
  93.     R0 = data pointer (your input)
  94.     R1 = number of times key was pressed (all key presses are buffered)
  95.     R2 = action code (if you have a string argument)
  96.  
  97. On exit from a command you may corrupt the registers R0-R11 and the flags.
  98. You should return V flag set and R0=error block on error. Some of the
  99. minibuffer calls with R2<>0 require you to return a result in R0. To detail
  100. the actual meaning of R0-R2 I have partitioned into cases below. Registers
  101. not mentioned are undefined.
  102.  
  103. If you want to call a command yourself, then please use the call
  104. Zap_ProcessCommand or Zap_CommandString. All calls from Zap are made by this
  105. method. See the file 'Commands' for the syntax used when typing a command
  106. into the keys file, or sending it to Zap_CommandString.
  107.  
  108. Data type = None (0)
  109. --------------------
  110.  
  111. Then R1=Number of times key pressed, and R0,R2 are not used. If the same
  112. command is bound to more than one key then all the buffered keypresses may
  113. not be due to the same key! Eg, the command UP. In the keys file it should
  114. appear with no parameters.
  115.  
  116. Data type = Byte list (1)
  117. -------------------------
  118.  
  119. Then R0=Pointer to a list of bytes, and R1=Number of bytes in the list. Eg,
  120. the command CHAR. In the keys file, the command should appear with a byte as
  121. parameter, eg CHAR 143 (or CHAR n where n is substituted for the key number
  122. it lies on). Thus if the user types A,B,C which have the commands CHAR 65,
  123. CHAR 66, CHAR 67 assigned to them, then the command will be called once with
  124. the list 65,66,67 if the keypresses were buffered.
  125.  
  126. Data type = Word list (2)
  127. -------------------------
  128.  
  129. Then R0=Pointer to a list of words, and R1=Number of words in the list. This
  130. works as for the byte list data type except that the command takes a word
  131. (4 bytes) as parameter.
  132.  
  133. Data type = String (3)
  134. ----------------------
  135.  
  136. All strings in this section are zero terminated. When you are passed R0 as
  137. the contents of the minibuffer, this excludes the prompt (see Zap_MiniWrite).
  138. In the following calls, R2 gives the action code distinguishing them.
  139.  
  140. CASE 1 - A string is specified after the command in the keys file (eg INSERT
  141.     "Hello").
  142.     
  143.     In this case you are called with R0=pointer to the string R1=number
  144.     of times the key was pressed. R2=0.
  145.     
  146. CASE 2 - No string specified in the keys file (eg INSERT).
  147.     
  148. In this case, a minibuffer is opened for the user to type in the string for
  149. the command to use. Most of the flags in the flags word control the way the
  150. minibuffer works. If the flags in bits 6+ are all clear then everything is
  151. handled automatically for you and you are called with R2=1 and R0=minibuffer
  152. contents when the user types RETURN. The detailed workings of the minibuffer
  153. are described below. Please supply a prompt (use b6) where possible.
  154.  
  155. The following happens before the minibuffer is opened on screen:
  156.  
  157. First of all, the minibuffer is cleared. If you wish to be called at this
  158. point (eg to add a prompt) then set b6 of your flags word and you will be
  159. called with R2=6 (R0,R1 undefined, R8-R10 setup as usual). You should then
  160. insert your prompt using Zap_MiniPrompt. Please look at Zap_MiniWrite for
  161. other ways of changing the minibuffer contents. It is possible that you may
  162. wish to kill the minibuffer at this point, before it is opened, as an null
  163. argument may sometimes be acceptable. For example, the command SAVEFILE
  164. (Emacs CTRL-X CTRL-S) only wants to open a minibuffer if the file is untitled
  165. (does not have a full path name). To do this, set b10 of your flags word (in
  166. addition to b6) and return R0=0 to open the minibuffer as usual, or
  167. R0=pointer to the string argument you want the command to be executed with.
  168. Your command will then be called again with R2=0 and R0=the parameter you
  169. have passed. This method ensures that the command is learnt correctly, as
  170. only command calls with R2=0 or R2=1 are learnt. Minibuffer setup calls with
  171. R2>1 are NOT learnt when you are in 'learn a key sequence mode'.
  172.  
  173. Now the minibuffer is opened on screen. The following happens when a key is
  174. typed by the user:
  175.  
  176. If you have b7 and b8 cleared then the key is inserted into the minibuffer
  177. automatically. ESCAPE and CTRL-G cause the minibuffer to close (without
  178. calling you) and RETURN causes your command to be called as described
  179. below.
  180.  
  181. If you want to intercept keys BEFORE they are acted on then set b8 of your
  182. flags word. You will then be called with R2=&8000+Zaps internal key number,
  183. and R0=the minibuffer contents string when the key is typed. After you have
  184. dealt with the key, you return a value in R0 to tell the minibuffer what to
  185. do with the key. There are 3 possible cases:
  186.  R0=-1        In this case no change is made to the minibuffer. Command
  187.         processing continues as normal (you will be called if b7
  188.         of your flags word set etc).
  189.  R0=key number    Then the given key is acted on as if it were the one typed.
  190.          Hence you will usually exit by SUB R0,R2,#&8000.
  191.  R0=&8000    In this case, the minibuffer is quitted as if Return had
  192.     +key number    been pressed (ie you are called with R2=1 as described
  193.         below). Then, AFTER the minibuffer has been closed, the
  194.         indicated key will be acted on as if typed in the editing
  195.         window. This enables keyboard-search to be quitted by, for
  196.         example, up arrow or ctrl X.
  197.  (If you just want to quit the minibuffer then return R0=&1B=ESCAPE).
  198.  One common use of this call is to trap the TAB key for completing an entry
  199. (eg command name or filename). If you set b9 of your flags word, then Zap
  200. assumes the buffer contains a file name and automatically completes the file
  201. name when TAB is pressed, saving you all the work!
  202.  
  203. If you want to examine the minibuffer contents AFTER the character has been
  204. entered into the minibuffer by Zap, you should set b7 of your flags word. You
  205. will then be called with R0=the minibuffer contents string, and R2=7. This
  206. call (as with the previous one) is made before the minibuffer contents is
  207. updated on screen and thus you don't need to call Zap_MiniUpdate if you alter
  208. the minibuffer contents. For example, search as you type (CTRL-S) uses this
  209. call to jump to the next match after every key press.
  210.  
  211. Zap enters keys into the minibuffer until the user presses ESCAPE, CTRL-G or
  212. RETURN. The first two quit the minibuffer.
  213.  
  214. When the user presses RETURN, you are called with R0=pointer to string typed
  215. into the minibuffer, and R2=1. As usual, the string pointed to by R0 does not
  216. include the prompt. You should then perform the command action, with this
  217. string as input. Usually, the minibuffer will be closed after your command
  218. has finished. If you wish it to remain open (eg the COMMAND command) then
  219. set b11 of your command word, and return R0=0 to close the minibuffer and
  220. R0=1 to leave it open when you exit from being called with R2=1.
  221.  
  222. The codes R2=1 and R2=0 should cause the same action to take place. This is
  223. to ensure the LEARN function works correctly. When a learnt function is
  224. executed, the minibuffer will not be opened again, but the command will be
  225. called with R2=0 and the previously typed string as input in R0. For example,
  226. if you learn the sequence: ctrl-S , "wibble" , RETURN typed in the
  227. minibuffer, then when this is played back the command SEARCHFORWARD will be
  228. called with R2=0 and R0="wibble" as opposed to opening the minibuffer. Only
  229. command calls with R2=0 or 1 are learnt.
  230.  
  231. Data type = Block (4)
  232. ---------------------
  233.  
  234. Then R0 = pointer to a data block (of command dependant format), and
  235. R1=number of times key pressed. This argument type is used by the command
  236. MULTICOMMAND which is used internally within Zap to execute a list of other
  237. commands. For example, when you type a sequence of commands separated by a
  238. ":" in the keys file, then this is converted to the one command MULTICOMMAND
  239. with data block as a list of the functions to call. You cannot put such a
  240. command in the keys file as there is no way of specifying a data block as
  241. parameter.
  242.  
  243.  
  244. EXAMPLE
  245. -------
  246.  
  247. The code below implements a simple command which asks you to enter a number
  248. into the minibuffer and then switches to that display mode. FNcall is a macro
  249. which calls the named Zap entry point (see E-Zapcalls for its definition).
  250.  
  251.     EQUD (3<<3)+(1<<6)        \ string argument + ask for prompt
  252.     .command_start
  253.     STMFD R13!,{R14}
  254.     TEQ R2,#6            \ is the minibuffer about to open
  255.     BEQ add_prompt
  256.     FNcall(Zap_MiniEval)        \ find the number typed
  257.     LDMVSFD R13!,{PC}        \ error
  258.     LDMCSFD R13!,{PC}        \ wasn't a valid number
  259.     FNcall(Zap_NewMode)        \ change mode
  260.     LDMFD R13!,{PC}            \ finished
  261.     .add_prompt
  262.     ADR R0,prompt_string
  263.     FNcall(Zap_MiniPrompt)        \ insert the prompt string
  264.     LDMFD R13!,{PC}         
  265.     .prompt_string
  266.     EQUS "New mode: "
  267.     EQUB 0
  268.     ALIGN
  269.  
  270. It is the offset of command_start that you must place in your command table,
  271. not the offset of the EQUD flags word before it. Note that the command
  272. performs the same action regardless of whether R2=0 or R2=1.
  273.  
  274.  
  275. Zap service calls
  276. -----------------
  277.  
  278. If the second word in your command table is non zero then it gives the
  279. module offset of a 'Zap service call handler'. This code is called at
  280. various points to tell you about things. In general the entry/exit
  281. conditions are:
  282.  
  283.     \E    R1=reason code and other registers may hold data.
  284.         R11=undefined
  285.         R12=Zaps workspace pointer as usual.
  286.     \X    You should preserve R1-R13 unless otherwise stated.
  287.         R0 and flags may be corrupted.
  288.         
  289. The (current) service calls are listed below. You should ignore unrecognised
  290. values in R1 so I can add more if necessary.
  291.  
  292. R1=0
  293. Zap is quitting and about to kill your module. Return R0=-1 to stop it.
  294. Your module will NOT be automatically killed if have no service call handler
  295. (for backwards compatibility).
  296.  
  297. R1=1
  298. Zap has just started but has not set up its heap yet.
  299.  
  300. R1=2
  301. Zap has started and set up its heap. You should use this call to claim any
  302. workspace via Zap_Claim.
  303.  
  304. R1=3
  305. Zap is deleting a file. R9=file block of file being deleted. (See E-File)
  306.  
  307. R1=4
  308. Zap is deleting a window. R8=window block of window being deleted.
  309. (See E-Windows)
  310.