home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / HISPEED2.LZH / MYCALC / MYCALC.DOC < prev    next >
Text File  |  1991-07-02  |  6KB  |  159 lines

  1.                   MyCalc - a HighSpeed accessory example
  2.  
  3.  
  4. 1. Introduction
  5. ---------------
  6. This  document contains the information required in order to  operate  the
  7. MyCalc  accessory,  but  does  not give  any  information  concerning  its
  8. programming - consult the source code files MYCALC.PAS and RPN.PAS.
  9.  
  10. 2. What is MyCalc?
  11. ------------------
  12. MyCalc  is  an accessory/application (can run as both;  .ACC  =  accessory
  13. operation,  .PRG  = application operation) operating as a  Reverse  Polish
  14. Notation (RPN) calculator.
  15.  
  16. 3. Files
  17. --------
  18. The MyCalc program set contains the following files :
  19.  
  20. MYCALC.PAS     - main program
  21. RPN.PAS        - the RPN evaluator unit
  22. MYCALC.I       - resource file constants from RCS 2.1
  23. MYCALC.DFN     - resource file definitions for RCS 2.1
  24. MYCALC.RSC     - resource file from RCS 2.1
  25.  
  26. 4. Installing MyCalc
  27. --------------------
  28. MyCalc  will always look for its resource file in the  current  directory,
  29. which   means  that  if  MyCalc  is  installed  as  an  accessory   (named
  30. MYCALC.ACC),  it  will look for the RSC file in the root directory of  the
  31. boot  disk.  If the RSC file can't be found,  the user  is  informed,  and
  32. MyCalc  will  install itself and wait  for  activation.  Upon  activation,
  33. MyCalc will again try to locate the RSC file in the current folder, and if
  34. it fails to do so,  then deny further operation.  If,  however,  the  file
  35. could be found, then it's loaded and stays resident together with MyCalc.
  36. If MyCalc is run as an application (named MYCALC.PRG),  then the RSC  file
  37. must be contained within the current directory; otherwise the program will
  38. abort.
  39.  
  40. 5. Executing MyCalc
  41. -------------------
  42. When  MyCalc is installed as accessory,  you activate it from  the  "Desk"
  43. menu.  If MyCalc can't open a window,  you will be told so, asked to close
  44. one and then reactivate MyCalc. This condition should never occur when run
  45. as application.
  46.  
  47. 6. Using MyCalc
  48. ---------------
  49. MyCalc can be used with the mouse and the keyboard.  Its functions are all
  50. implemented with use of the numeric keypad in mind - this implies that the
  51. [ ( ] and [ ) ] keys don't behave as expected (see below).
  52. The MyCalc window can be moved and topped as any other GEM window,  but of
  53. course not sized.
  54.  
  55. 6.1. Mouse usage
  56. ----------------
  57. When  the mouse is moved to one of the buttons,  it  will  highlight,  and
  58. reverse when the mouse is moved away again.  You select a number/operation
  59. by highlighting a button and then pressing the left mouse button.
  60. When through using MyCalc,  you click the "Close" box on the upper left of
  61. the window.
  62.  
  63. 6.2. Keyboard usage
  64. -------------------
  65. The following keys have an operation with MyCalc :
  66.  
  67. 0..9      : digits
  68. .         : radix point
  69. +         : add
  70. -         : subtract
  71. *         : multiply
  72. /         : divide
  73. (         : sign inversion
  74. )         : swap top elements (see below)
  75. Enter     : push number onto stack
  76. Backspace : delete last digit/clear top of stack
  77. Esc       : close MyCalc window
  78.  
  79. Both keypads (alphanumeric and numeric) can be used.
  80.  
  81. 7. How to calculate
  82. -------------------
  83. As mentioned above, MyCalc utilizes Reverse Polish Notation. This involves 
  84. a  new  way  of thinking when evaluation  expressions,  as  the  following 
  85. examples show :
  86.  
  87. normal         RPN
  88. ------------------
  89. 1+2            1 ENTER 2 +
  90. (1+2)*3        1 ENTER 2 + 3 *
  91. (1+2)*(3+4)    1 ENTER 2 + 3 ENTER 4 + *
  92.  
  93. 8. MyCalc's implementation of RPN
  94. ---------------------------------
  95. MyCalc implements a Hewlett-Packard like system of RPN,  that is,  with  a 
  96. four element stack made up of the registers x,  y, z and t. The philosophy 
  97. behind  RPN  is  to enter the operands on the stack  and  the  execute  an 
  98. operation (e.g. addition). The stack layout can be visualized like this :
  99.  
  100. t    - bottom of stack
  101. z
  102. y
  103. x    - top of stack, the element shown in the display
  104.  
  105. Most people would probably say,  the layout is upside down, but that's the 
  106. way Hewlett Packard shows it...
  107.  
  108. Now,  when  an expression like 1+2 is evaluated,  the following happens  : 
  109. First,  the  value 1 is pushed onto the stack (into x).  Then 2 is  pushed 
  110. into x,  thereby forcing the old value into y. The addition then pops both 
  111. values off the stack, adds them and pushes the result back onto the stack. 
  112. The below table should clarify this :
  113.  
  114. reg.      operation
  115. ---------------------------------
  116.           1    ENTER     2    +
  117. ---------------------------------
  118. x         1    1         2    3
  119. y              1         1
  120. z
  121. t
  122.  
  123. As you can see,  the ENTER operation pushes the value 1 into y, but at the 
  124. same  time  enables x to be overwritten by the value  2.  This  is  termed 
  125. "disabling stack-lift".  Backspace does the same,  when a value is cleared 
  126. (made 0.00000), i.e. allows the x-register value to be overwritten.
  127.  
  128. Let's look at (1+2) * (4-5) :
  129.  
  130. reg.      operation
  131. ---------------------------------------------------------------
  132.           1    ENTER     2    +    4    ENTER     5    -    *
  133. ---------------------------------------------------------------
  134. x         1    1         2    3    4    4         5   -1   -3
  135. y              1         1         3    4         4    3
  136. z                                       3         3
  137. t
  138.  
  139. Finally,  one special property of the t register should be mentioned : Its 
  140. value  can only be changed by pushing numbers onto the stack,  and not  by 
  141. popping. Let's illustrate :
  142.  
  143. reg       operation
  144. ---------------------------------------------------------------
  145.           1    ENT  2    ENT  3    ENT  4    +    +    +    +
  146. ---------------------------------------------------------------
  147. x         1    1    2    2    3    3    4    7    9   10   11
  148. y              1    1    2    2    3    3    2    1    1    1
  149. z                        1    1    2    2    1    1    1    1
  150. t                                  1    1    1    1    1    1
  151.  
  152. In  the  above  illustrations,  we haven't  shown  the  register  contents 
  153. unaffected by our operations. ENT is an abbreviation for ENTER.
  154.  
  155.  
  156. Finally,  we  wish you best of luck with experimenting with the  HighSpeed 
  157. Pascal MyCalc accessory.
  158.  
  159.