home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_2 / issue_04 / currdirrm / CURRDIRTXT < prev   
Text File  |  1995-06-22  |  4KB  |  70 lines

  1. As a new Archimedes user, coming from the IBM PC environment I am familiar
  2. with the idea of a modifiable prompt as described in the Users Guide to
  3. provide an  example of the use of the SETMACRO command.
  4.  
  5. "SETMACRO CLI$PROMPT <SYS$TIME>"  will provide the current time as a prompt
  6. by re-evaluating the prompt string each time it is used, and the SYS$TIME
  7. variable is maintained by the operating system.  Personally I find the most
  8. useful information to have at the prompt is the path or current directory,
  9. especially since I have a hard disk.  It is suprising that Arthur doesn't
  10. provide a system variable to  keep track of the current directory.  I decided
  11. to find out what is involved in creating and maintaining such a variable.
  12.  
  13. The current directory is always changed, whether by a program or a command
  14. via the OS_FSControl SWI. When a SWI is issued by a program, control is
  15. passed via a "vector" or pointer, and this vector can be "claimed" or
  16. redirected to your own piece of code.  It is then up to you whether you pass
  17. control on to the previous owner of the vector or "intercept" it entirely and
  18. replace the functions being requested with your own.
  19.  
  20. The logic behind my program is as follows:
  21.  - The program is entered via the claimed FSControlV vector.
  22.  - If the function requested is not set current directory, then pass control
  23.    onto the previous owner of the vector.
  24.  - If set current directory(i.e. R0=0) is requested, then ensure that we regain
  25.    control after the directory has been changed, by providing our return
  26.    address pushed onto the stack.
  27.  - On return we use the SWI OS_GBPB to "read current directory".
  28.  - Then issue the OS_SetVarVal SWI to update the variable.
  29.  
  30. Now if I am going to start interfering with the operating system by claiming 
  31. vectors, I want to be sure that the memory into which I place my code is not 
  32. going to inadvertently be overwritten by some application or utility.  Else all
  33. functions provided by that SWI, and not just changing the current directory
  34. will be disabled!  The ideal way to see that your interfering piece of code
  35. is well looked after, is to package it as a module.  
  36.  
  37. Other benefits of writing the program as a module are the ready made commands
  38. to install and remove it with RMLOAD and RMKILL, and predefined entry points
  39. for initialisation, finalisation and service call handler. The first two
  40. entry points are almost self explanatory, the initialisation code is called
  41. when the module is loaded and also after the RMA has been tidied. The
  42. finalisation code is entered for the OS_Module call with reason codes Tidy,
  43. Reinit, Delete and Clear, also if a module is loaded twice, the old one is
  44. killed.  
  45.  
  46. The use of the service call handler entry point is not as immediately
  47. obvious. Service calls are issued by OS_ServiceCall and are identified by the
  48. service number in R1. They fall into two categories either soliciting
  49. information or action because of an unknown - e.g. unknown file type,
  50. command, *status or OS_Word.  Or else informing modules of an event that may
  51. be of interest to them -  e.g. Error, StartUpFS, Reset, Keyboard handler, or
  52. Pre-reset.   
  53.   
  54. CurrDirRM was initially written without a service call handler, but the 
  55. claimed vector was mysteriously being returned to its previous owner, which
  56. left the module useless and what was more annoying it was impossible to
  57. reinitialise, kill or tidy as it got an error whenever it tried to release a
  58. vector it no longer owned! I eventually saw the connection between, soft and
  59. machine resets and the "reset" vector. I used the service call handler to
  60. check for Reset and Pre-reset service calls, and set a flag to inform the
  61. finalisation code not to worry about releasing the vector.
  62.  
  63. The module once assembled and saved to the modules directory, only occupies
  64. &13A bytes which even on a 512K system isn't too great a sacrifice.  To
  65. install it and incorporate it into a prompt, add the following lines to your
  66. !BOOT program:
  67.  
  68. *RMLOAD $.Modules.CurrDirRM
  69. *SETMACRO Cli$Prompt <Curr$Dir>==>
  70.