home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / proclc / popcalc.txt < prev   
Encoding:
Text File  |  1994-03-22  |  12.7 KB  |  309 lines

  1.  
  2.      PopCALC - Programmers Calculator, Version 1.00
  3.          Copyright (c) 1994 by Omega Point, Inc.
  4.  
  5.  
  6. INTRODUCTION
  7.  
  8. PopCALC is a TSR integer calculator using C operator/expression syntax.
  9. In addition to C operator set, it includes ROTATE operator for assembler
  10. programmers and a special Right-Assignement operator usefull for concise 
  11. expressions. The integers may have word size 1,2,4 bytes and may be
  12. treated as signed and unsigned. Output radix may be set to Decimal,
  13. Hex and Binary, and input expressions may have mixed radix numbers.
  14. PopCALC allows multiple complex expressions separated by semicolon,
  15. and it has 26 variables labeled with letters A through Z. The expression
  16. editor has insert and overtype mode, and supports Cursor, Del, Backspace,
  17. Home, End, Tab, Back-Tab editing keys. It also has Ctl-Left, Ctl-Right
  18. arrow commands, which skip from one to another expression and evaluate
  19. them. Any computed result may be passed on to the interrupted foreground
  20. application in C or ASM format. Calculator window may be moved to any 
  21. place on the screen. Command line switches have access to any of 
  22. PopCALC-s internal settings/modes.
  23.  
  24. With all these features, PopCALC occupies only 6.6K of RAM while in
  25. resident mode and has 10K EXE file. The small TSR size (for a C program)
  26. is due to elimination of startup code (command line parser)  and data
  27. (signon screens) done automatically by CodeRunneR (tm). Additionally,
  28. CodeRunneR's library is optimized for interactive pop-up application.
  29.  
  30.  
  31. INVOKING CALCULATOR WINDOW
  32.  
  33. Once loaded, PopCALC is always a single key away. If your computer has
  34. new style keyboard, press Right-Alt key to bring-up the calculator.
  35. On older style keyboards, press Alt-SPACE. To return back to the
  36. foreground application, press <Esc>, or Right-Alt. The state of the
  37. PopCALC is preserved between invocations.
  38.  
  39.  
  40. MOVING CALCULATOR WINDOW
  41.  
  42. You can move the calculator window (line) Up or Down using arrow keys.
  43. If the video adapter supports more then 25 lines, the window will
  44. reach any line on the screen.
  45.  
  46.  
  47. UNLOADING PopCALC FROM MEMORY
  48.  
  49. PopCALC may be unloaded from memory by pressing Alt-X while in the
  50. calculator window. The unload should be requested only if PopCALC is
  51. the last TSR loaded. Although CodeRunneR has a function to check for this,
  52. it was not used in this program, to save space. Therefore, PopCALC will
  53. always unload, possibly deactivating other TSR-s loaded after PopCALC.
  54.  
  55.  
  56. EXPRESSION ENTRY & EDITING
  57.  
  58. Expressions are entered in a conventional way (a la typical editor). Use
  59. regular cursor keys to move around. <Home> key moves first to the beginning
  60. of the expression, unless already there in which case it moves to the
  61. beginning of line. Likewise, <End> moves to the end of expression, then
  62. to the end of line. <Tab> and <Back-Tab> cycle between the four points of
  63. <Home>,<End> keys. <Del> deletes current character, <Backspace> deletes
  64. previous character.
  65.  
  66. <Ins> toggles between insert and overtype modes. In default mode PopCALC
  67. comes up in overtype mode (underline cursor). The insert mode has full
  68. blinking block cursor. The mode persists between calculator pop-ups.
  69.  
  70.  
  71. NUMBER ENTRY
  72.  
  73. Numbers may be entered in Decimal, Hex and Binary radix. Sign + or - may
  74. precede the digits. Numbers are internally kept as 32-bit integers.
  75.  
  76. DECIMAL: Max 10 digits, Max number: 4,294,967,295
  77. HEX:     Prefixed with 0x or 0. Max 8 digits, Max number 0xFFFFFFFF
  78. BINARY:     Prefixed with ` (Back-QUOTE). Max 32 digits.
  79.  
  80. Comma cannot be placed between digits.
  81.  
  82.  
  83. OUTPUT RADIX
  84.  
  85. Output radix may be set using 3 Control Key commands (or the command line 
  86. switches). The keys are:
  87.  
  88. Control D    - Set decimal radix
  89. Control H    - Set hex radix
  90. Control B    - Set binary radix
  91.  
  92. Following these three commands, the expression is re-evaluated and result is
  93. displayed in the new radix.
  94.  
  95.  
  96. OPERATORS
  97.  
  98. The operators follow standard C precedence rules. They are shown below,
  99. in order of decreasing precedence, and with sub-groups having same
  100. precedence:
  101.  
  102. -----------------------------------------
  103. OPER    DESCRIPTION
  104. -----------------------------------------
  105.  (    Open parentheses (20 levels deep)
  106. -----------------------------------------
  107.  ~    Bitwise Complement
  108.  -    Unary minus
  109.  +    Unary plus
  110. -----------------------------------------
  111.  *    Multiply
  112.  /    Divide
  113.  %    Modulo
  114.  \    Alternate symbol for modulo
  115. -----------------------------------------
  116.  +    Add
  117.  -    Substract
  118. -----------------------------------------
  119.  <<    Shift Left
  120.  >>    Shift Right
  121.  [[    Rotate Left
  122.  ]]    Rotate Right
  123. -----------------------------------------
  124.  &    Biwise AND
  125. -----------------------------------------
  126.  ^    Bitwise XOR
  127. -----------------------------------------
  128.  |    Bitwise OR
  129. -----------------------------------------
  130.  '    Right Assign (shows as ARROW)
  131. -----------------------------------------
  132.  )    Closed parentheses
  133. -----------------------------------------
  134.  ;    Statement separator
  135. -----------------------------------------
  136.  
  137. The non standard ROTATE operators [[,]] rotate bit pattern to the left or
  138. right, in the same manner as assembler ROL and ROR instructions. The
  139. outcome depends on the (unsigned) word size as follows:
  140.  
  141. 32-bit    X [[ 3    same as:    (X << 3) + (X >> (32-3))
  142. 16-bit    X [[ 3    same as:    (X << 3) + (X >> (16-3))
  143.  8 bit    X [[ 3    same as:    (X << 3) + (X >> ( 8-3))
  144.  
  145.  
  146. WORD SIZE COMMANDS (Ctl-C, Ctl-I, Ctl-L)
  147.  
  148. All integer computations are done modulo some power of 2 (i.e. only low
  149. N bits of the result is kept on overflow). PopCALC provides for 3 word
  150. sizes: Char (8-bits), Int (16-bits), Long (32-bits). These sizes are set
  151. using commands Ctl-C, Ctl-I, Ctl-L respectively.
  152.  
  153. For most operators, the difference is only that the arguments and result
  154. are stripped of excessive high bits. The only operators computed differently
  155. are ROTATE operators.
  156.  
  157. NOTE: Variables are not affected by these commands. Only the variables
  158. which are being assigned values in the current expression will have
  159. values reduced to proper width. Variables which are used in the expression,
  160. but not assigned value by the expression, are unchanged.
  161.  
  162.  
  163. SIGNED/UNSIGNED ARITHMETIC (Ctl-S, Ctl-U)
  164.  
  165. Operators can view same numbers as signed and unsigned. The unsigned numbers
  166. are always positive and range between 0 and M (M depends on word size).
  167. The signed numbers have values between -M/2-1 and +M/2 (inclusive).
  168. These boundaries are shown in the table below for different word sizes:
  169.  
  170. -----------------------------------------------------------------------
  171.                   UNSIGNED                 SIGNED
  172. -----------------------------------------------------------------------
  173. Word size      MIN           MAX            MIN          MAX
  174. -----------------------------------------------------------------------
  175.   8 bits       0           255           -128              +127
  176. -----------------------------------------------------------------------
  177.  16 bits       0        65,535          -32,768           +32,767
  178. -----------------------------------------------------------------------
  179.  32 bits       0  4,294,967,295   -2,147,483,648   +2,147,483,647
  180. -----------------------------------------------------------------------
  181.  
  182. Right shift operator will fill in 1-s when in signed mode, and 0-s in
  183. unsigned mode. Divide and Modulo operators will similarily produce
  184. different result when in signed mode. Other operators work same, with
  185. only the displayed result showing the different representation of the
  186. same bit pattern. The only exceptional case is divide (or modulo) by
  187. zero, which allways produces maximal unsigned number (or 0); such number
  188. will show as -1 if Signed representation is used.
  189.  
  190.  
  191. VARIABLES AND ASSIGNEMENT OPERATOR (')
  192.  
  193. PopCALC has 26 variables which are labeled as single letters A-Z (upper and
  194. lower case are same). The assignement operator ' (Single QUOTE) assigns value
  195. of the sub-expression on its left side to the varible on its right side.
  196. For this reason it is actually DISPLAYED as an ARROW pointing to the right.
  197. The value assigned is the current value computed up to that point in the
  198. expression. From the precedence table, it is clear that this value includes
  199. all the items to the right, until the first Unbalanced Open Parentheses.
  200. MULTIPLE assignements are allowed in the same statement, leading to very
  201. concise expressions.
  202.  
  203. Assignement Examples:
  204.  
  205. PopCALC            C Equivalent
  206. -----------------------------------------------------------------------
  207. 125'x            x=125;
  208. 3+2'x            x=3+2;
  209. 3'x+2'y            x=3; y=3+2;
  210. 7*(3'x+2'y)'e*(1+5)'z    x=3; y=3+2; e=7*(3+2); z=7*(3+2)*(1+5);
  211. a+1'x+b*(c-d'y)'z    x=a+1; y=c-d; z=a+1+b*(c-d);
  212. -----------------------------------------------------------------------
  213.  
  214.  
  215. STATEMENT EVALUATION (Enter key or = key)
  216.  
  217. The statements are separated with ;  (Semicolon). You can enter as many
  218. statements as will fit on one line. When <Enter> key is pressed (or =)
  219. the statements are evaluated orderly from left to right until the current
  220. statement is evaluated (i.e. statement under cursor). The last result
  221. is then displayed. In order to evaluate all entered statements, press
  222. <End> to move to the end of line then press <Enter>.
  223.  
  224. If an ERROR is found, a Question mark is shown and the cursor is placed
  225. on the improper statement.
  226.  
  227.  
  228. SKIPPING BETWEEN EXPRESSIONS
  229.  
  230. Press Control with Left or Right cursor key. The cursor will skip from
  231. one to another expression, evaluating on each step everything to the
  232. right, and displaying the value of the statement under cursor.
  233.  
  234. CLEARING LINE
  235.  
  236. The line is not normally cleared following evaluation. To evaluate and
  237. clear the line hold Shift key and press <Enter>, or press F10. The line
  238. is not cleared if an error was found during evaluation. In that case,
  239. the cursor is placed on the bad statement.
  240.  
  241.  
  242. SENDING RESULT TO APPLICATION ( F5, F6 )
  243.  
  244. PopCALC can send current result to the foreground application as a sequence
  245. of keystrokes. The keystrokes are sent using CodeRunneR's Tiny Scheduler,
  246. in order not to overflow some applications keystroke buffers. The next
  247. keystroke is sent only when application accepts the previous keystroke,
  248. thus the input speed depends on application. The number is sent exactly
  249. as shown in the result field for Decimal radix. For Binary and Hex radix,
  250. the output dependes on Function key used. F5 will produce C style output,
  251. and F6 Assembler style output.
  252.  
  253.  
  254.  
  255. COMMAND LINE OPTIONS
  256.  
  257. Command line options allow you to set-up calculator in the desired mode of
  258. operation when it loads up. The options should be separated by comma or
  259. space. Followng is the table of options:
  260.  
  261. SWITCH    Default    DESCRIPTION
  262. -------------------------------------------------------------------
  263.   H           Hex radix
  264.   D    Yes       Decimal Radix
  265.   B           Binary Radix
  266. -------------------------------------------------------------------
  267.   S    Yes       Signed arithmetic
  268.   U           Unsigned arithmetic
  269. -------------------------------------------------------------------
  270.   L    Yes       Word size 32 bits (long)
  271.   I           Word size 16 bits (int)
  272.   C           Word size  8 bits (char)
  273. -------------------------------------------------------------------
  274.  1 to 25       Row for PopCALC window, greater on some monitors
  275. -------------------------------------------------------------------
  276.  
  277.  
  278.  
  279.         NOTES ON SOURCE CODE
  280.  
  281.  
  282. The source code on the diskette contains three C files PC.C, PCID.C and
  283. PCIC.C as well as a file CR.H which is one of CodeRunneR's header files
  284. and PCALC.MAP file containing all of PCALC.EXE public symbols. To link
  285. the source code into an executable file, you will also need CR.LIB
  286. which is CodeRunneR library. Microsoft C or Turbo C may be used (inquire
  287. about other C compilers). If you don't yet have CodeRunneR, the source
  288. and the MAP file will still let you do some minor customizations (like
  289. screen colors, and startup defaults). You can patch these using DEBUG.
  290. The CodeRunneR package contains the latest PopCALC source, as well as
  291. five other utilities (including a Floating Point calculator, ASCII/Color
  292. chart, .. and other usefull TSR-s).
  293.  
  294. File PCID.C contains startup screens and other initialization data. It
  295. shows CodeRunneR's compressed screen image representation.
  296.  
  297. File PCIC.C contains main() and non-TSR portion of the code. It shows how
  298. to eliminate startup code and data, and how to switch to TSR mode. It also
  299. shows how to setup CodeRunneR's Tiny Scheduler.
  300.  
  301. File PC.C is the TSR part of PopCALC. It demonstrates how simple it
  302. can be to write TSR-s with CodeRunneR. The bulk of its code is the
  303. calculator engine, and a small fraction deals with TSR aspect. Most
  304. of the TSR related functions are done by CodeRunneR. The scheduler
  305. used to send keystrokes to the applications is CodeRunneR's Tiny
  306. Scheduler which allows for simple one-shot events. The reason for using
  307. scheduler is that some applications flush keyborad before each new key.
  308. The scheduler adds new key into the buffer only if the buffer is empty.
  309.