home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR8 / CALC_SRC.ZIP / ACALC.S next >
Text File  |  1993-07-28  |  20KB  |  591 lines

  1. /*
  2.                   Tuesday, 27 July 1993
  3. */
  4.  
  5. /******************* Global Constants and Variables ***********************/
  6.   Constant
  7.      MaxField = 17,        // max size of input field
  8.      FieldX      = 6,        // horiz location of start of field
  9.      FieldY      = 2            // verticle location of field
  10.  
  11.  
  12.   String
  13.      Input[MaxField]  = '',        // keyboard input accumulator
  14.      GetStr[MaxField]  = '',    // Word under cursor
  15.      BaseLtr[1] = 'd'                    // number base indicator
  16.  
  17.  
  18.   Integer
  19.      UpLtCol  = 10,        // initial location for calc window
  20.      UpLtRow  = 10,        // initial location for calc window
  21.      BotRtCol = 34,        // initial location for calc window - UpLtCol+24
  22.      BotRtRow = 15,        // initial location for calc window - UpLtRow+5
  23.      X      =  0,                // current input
  24.      Y      =  0,                // previous input
  25.      Base      = 10,            // number base
  26.      WordSize = 16,      // width of word to flip, affects Not, And, Or, Xor
  27. // Booleans
  28.      New     = True,  // Flags NEW input
  29.      InitFlag = False, // flag to initiate vars on firs load only
  30.      HelpFlag = False, // remember to trap keypress when back from help
  31. // Math flags
  32.      Add     = False,                // <----+
  33.      Subtract = False,        //            |
  34.      Multiply = False,        //            |
  35.      Divide      = False,        //            |
  36.      Modulo      = False,        //            |-- flags to control DoMath()
  37.      ShftRt      = False,        //            |     when "=" key is pressed
  38.      ShftLt      = False,        //            |
  39.      AndFlag  = False,        //            |
  40.      OrFlag      = False,        //            |
  41.      XorFlag  = False,        //            |
  42.      NotFlag  = False            // <----+
  43.  
  44.  
  45. /************************************************************************/
  46. /*              Calculator helper functions                  */
  47. /************************************************************************/
  48. Proc InitRegs()        // initiate variable initial values
  49.  
  50.     X         = 0                // zero input value
  51.     Y         = 0                // zero previous input value
  52.     Base     = 10            // default to decimal (set via global var???)
  53.     BaseLtr  = 'd'    // decimal indicator
  54.     InitFlag = true    // we're loaded...
  55. End InitRegs
  56. //-------------------------------------------------------------------------
  57. Proc ClrField()      // Used to clear numbers from field
  58.     Vgotoxy(FieldX,FieldY)  // on screen when being updated with new
  59.     PutLine(' ',MaxField-1) // data.
  60. End ClrField
  61. //-------------------------------------------------------------------------
  62. Proc UpdateField()  // update display
  63.     String Filler[1]=Iif(Base == 2, '0', ' ')    // fill field 0s for binary
  64.                                                                                         //  else blanks
  65.     ClrField()
  66.     Vgotoxy(FieldX,FieldY)
  67.     PutLine(Format(X:MaxField-1:Filler:Base,BaseLtr:1),MaxField)
  68. End UpdateField
  69. //-------------------------------------------------------------------------
  70. Proc SetWordSize()  // set number of bits to toggle with AND/OR/XOR/NOT
  71.  
  72.     Integer    key,
  73.                     OldAttr
  74.  
  75.     Vgotoxy(FieldX,FieldY)                                    // locate
  76.     PutLine('WordSize?',MaxField)                        // and place prompt
  77.     OldAttr = Set(Attr,Query(MenuTextAttr))    // set color to match menus
  78.     Vgotoxy(FieldX,FieldY+1)                                // locate
  79.     PutLine('0FEDCBA987654321',MaxField-1)    // and add wordsize indicators
  80.     VgotoXY(FieldX+(MaxField-(1+WordSize)),FieldY+1)    // locate on current size
  81.     PutAttr(Query(MenuTextLtrAttr),1)    // highlight it
  82.     Set(Attr,OldAttr)                                    // reset color
  83.     key = GetKey() & 0FFh                            // get keys char value
  84.     Case key
  85.         When 30h..39h,41h..46h,61h..66h                // number 0..16
  86.           Vgotoxy(FieldX+Maxfield-3,FieldY)        // locate to show choice
  87.             If Val(Chr(Key),16)    // if not 0
  88.                 WordSize = Val(Chr(Key),16)
  89.             Else                              // if 0 force to 10h
  90.                 WordSize = 16
  91.             EndIf
  92.             PutLine(Format(WordSize:2:'0':16,'h'),3)  // display value for
  93.             Delay(4)            // only short time
  94.             UpdateField()    // redisplay
  95.         When 01Bh                // When Esc do nothing
  96.         UpdateField()        // redisplay
  97.     Otherwise
  98.         SetWordSize()        // recurse until 0..F or Esc
  99.     EndCase
  100.     Set(Attr,Query(MenuTextAttr))                 // set color to match menus
  101.     VgotoXY(FieldX,FieldY+1)                 // locate and replace tic marks
  102.     PutLine(chr(249)+'   '+chr(249)+'   '+chr(249)+'   '+Chr(249),MaxField)
  103.     VgotoXY(FieldX+(MaxField-(1+WordSize)),FieldY+1)// locate wordsize point
  104.     PutLine(Chr(24),1)                     // place arrow indicator
  105.     VgotoXY(FieldX+(MaxField-(1+WordSize)),FieldY+1)// back to arrow location
  106.     PutAttr(Query(MenuTextLtrAttr),1)             // highlight it
  107.     Set(Attr,OldAttr)                         // reset color
  108. End SetWordSize
  109. //-------------------------------------------------------------------------
  110. Proc Overflow()      // display warning of pending overflow condition
  111.     Vgotoxy(FieldX,FieldY)             // locate for output
  112.     PutLine('OVERFLOW',MaxField)  // Error Msg
  113.     Delay(9)                 // pause for a bit
  114. End OverFlow
  115. //-------------------------------------------------------------------------
  116. Proc DoMath()         // Do the math
  117.  
  118.     Integer i = 1      // scratch counter
  119.  
  120.     String XStr[MaxField-1] = '',   // holds binary string representaion of X
  121.         YStr[MaxField-1] = '',   // holds binary string representaion of Y
  122.         NewStr[MaxField-1] = '', // holds binary string representaion
  123.         AddZeros[MaxField-1] = ''    // accumulates 0's for SHL
  124.  
  125.     If Add
  126.         If MaxInt - Iif(Y<0,-y,y) >= Iif((X<0 and Y<0),-X,X)  /*check for overflow*/
  127.           Y = X+Y
  128.           X = Y
  129.         Else
  130.             X = Y
  131.             OverFlow()
  132.         EndIf
  133.         Add = False
  134.     ElseIf Subtract
  135.     // (check for overflow) or (test for underflow ( > -MaxInt))
  136.         If (X > 0 and Y > 0) OR (MaxInt - Iif(Y<0,-y,y) >= Iif((X<0 and Y<0),-X,X))
  137.             Y = Y-X
  138.             X = Y
  139.         Else
  140.             X = Y
  141.             OverFlow()
  142.         EndIf
  143.         Subtract = False
  144.     ElseIf Multiply
  145.         If MaxInt/Iif(X<0 ,-X,X) > Iif(Y<0,-Y,Y) or X == 0 // check for overflow
  146.             Y = Y*X
  147.             X = Y
  148.     Else
  149.         X = Y
  150.         OverFlow()
  151.     EndIf
  152.         Multiply = False
  153.     ElseIf Divide
  154.         Y = Y/X
  155.         X = Y
  156.         Divide = False
  157.     ElseIf Modulo
  158.         Y = Y Mod X
  159.         X = Y
  160.         Modulo = False
  161.     ElseIf ShftRt
  162.         XStr = Format(Y:MaxField-1:'0':2)
  163.         X = Val(SubStr(XStr,1,Length(XStr)-x),2)    //clip off X digits
  164.         ShftRT = False
  165.     ElseIf ShftLt
  166.         XStr = Format(Y:MaxField-1:'0':2)
  167.         Repeat
  168.             AddZeros = AddZeros + '0'                              // add X trailing 0s to Y
  169.             i = i + 1
  170.         Until i > x
  171.         X = Val(SubStr(XStr,1+x,Length(XStr))+AddZeros,2)    //place Val in X
  172.         ShftLt = False
  173.     ElseIf AndFlag
  174.         XStr = Format(X:MaxField-1:'0':2)
  175.         YStr = Format(Y:MaxField-1:'0':2)
  176.         NewStr = SubStr(YStr,1,(MaxField-WordSize)-1)
  177.         i = MaxField - WordSize
  178.         Repeat
  179.             NewStr = NewStr + Str(Val(Ystr[i]) & Val(XStr[i]))
  180.             i = i + 1
  181.         Until i > Length(YStr)
  182.         X = Val(NewStr,2)
  183.         AndFlag = False
  184.     ElseIf OrFlag
  185.         XStr = Format(X:MaxField-1:'0':2)
  186.         YStr = Format(Y:MaxField-1:'0':2)
  187.         NewStr = SubStr(YStr,1,(MaxField-WordSize)-1)
  188.         i = MaxField - WordSize
  189.         Repeat
  190.             NewStr = NewStr + Str(Val(Ystr[i]) | Val(XStr[i]))
  191.             i = i + 1
  192.         Until i > Length(YStr)
  193.         X = Val(NewStr,2)
  194.         OrFlag = False
  195.     ElseIf XorFlag
  196.         XStr = Format(X:MaxField-1:'0':2)
  197.         YStr = Format(Y:MaxField-1:'0':2)
  198.         NewStr = SubStr(YStr,1,(MaxField-WordSize)-1)
  199.         i = MaxField - WordSize
  200.         Repeat
  201.             NewStr = NewStr + Str(Val(Ystr[i]) ^ Val(XStr[i]))
  202.             i = i + 1
  203.         Until i > Length(YStr)
  204.         X = Val(NewStr,2)
  205.         XorFlag = false
  206.     ElseIf NotFlag                                            // only effects X register
  207.         XStr = Format(X:MaxField-1:'0':2)
  208.         i = MaxField - WordSize
  209.         Repeat
  210.             if XStr[i] == '0'                                // if 0 toggle to 1
  211.                 XStr = (SubStr(XStr,1,i-1)+'1'+SubStr(XStr,i+1,Length(XStr)))
  212.             Else                                                        // if 1 toggle to 0
  213.                 XStr = (SubStr(XStr,1,i-1)+'0'+SubStr(XStr,i+1,Length(XStr)))
  214.             EndIf
  215.             i = i + 1
  216.         Until i > Length(XStr)                         // done
  217.         X = Val(XStr,2)                                      // get bitwise NOT value in X
  218.         NotFlag = False
  219.     EndIf
  220.     UpdateField()
  221. End DoMath
  222. //-------------------------------------------------------------------------
  223. Proc BinHexDecOct(Integer MyBase)        // Dec Hex or Binary Oct mode toggles
  224.  
  225.     If MyBase == 16
  226.         BaseLtr = 'h'
  227.         Base = 16
  228.     EndIf
  229.     If MyBase == 10
  230.         BaseLtr = 'd'
  231.         Base = 10
  232.     EndIf
  233.     If MyBase == 8
  234.         BaseLtr = 'o'
  235.         Base = 8
  236.     EndIf
  237.     If MyBase == 2
  238.         BaseLtr = 'b'
  239.         Base = 2
  240.     EndIf
  241.     If NOT New
  242.         Input = Str(X,Base)  // make sure input string matches register base
  243.     EndIf
  244.     UpdateField()
  245. End BinHexDecOct
  246. //-------------------------------------------------------------------------
  247. Proc ShadowBox(Integer SwitchOn)            // turn shadow under calc on or off
  248.     If SwitchOn
  249.         PopWinOpen(UpLtCol+1,UpLtRow+1,BotRtCol+1,BotRtRow+1,1,'',Color(Black on Black))
  250.     Else
  251.         PopWinClose()                                            // turn shadow off
  252.     EndIf
  253. End ShadowBox
  254. //-------------------------------------------------------------------------
  255. Proc CalcBox(Integer Open)    // place the calculator display on the screen
  256.                                                         // or turn it off
  257.     Integer
  258.         OldAttr
  259.     String
  260.         Tic[13] = chr(249)+'   '+chr(249)+'   '+chr(249)+'   '+Chr(249)
  261.  
  262.     If Open
  263.         PopWinOpen(UpLtCol,UpLtRow,BotRtCol,BotRtRow,1,'Integer Calculator',Query(MenuBorderAttr))
  264.         VgotoXY(1,1)                      // get video cursor in box
  265.         OldAttr = Set(Attr,Query(MenuTextAttr))  // set color to match menus
  266.         clrscr()                              // clear box
  267.         VgotoXY(FieldX,FieldY+1)
  268.         PutLine(Tic,MaxField)              // nibble tic marks
  269.         VgotoXY(FieldX+(MaxField-(1+WordSize)),FieldY+1)
  270.         PutLine(Chr(24),1)                  // wordsize indicator
  271.         VgotoXY(FieldX+(MaxField-(1+WordSize)),FieldY+1)
  272.         PutAttr(Query(MenuTextLtrAttr),1)      // highlight it
  273.         VgotoXY(1,FieldY+2)                 // locate for help line
  274.         PutLine('Esc to Exit, H for help',23)     // short help
  275.         Set(Attr,Query(TextAttr))  // set the attribute to reg edit screen
  276.         ClrField()
  277.     Else
  278.         PopWinClose()  // all done, close window
  279.     EndIf
  280. End CalcBox
  281. //-------------------------------------------------------------------------
  282. Proc MoveBox(integer LtRt, integer UpDn)  // move the box around the screen
  283.  
  284.     If (UpLtCol + LtRt > 0) AND (UpLtCol + LtRt + 24 < Query(ScreenCols))
  285.         UpLtCol = UpLtCol + LtRt
  286.         BotRtCol = UpLtCol+24
  287.     Else
  288.         Return()
  289.     EndIf
  290.     If (UpLtRow + UpDn > 0) AND (UpLtRow + UpDn + 5 < Query(ScreenRows))
  291.         UpLtRow = UpLtRow + UpDn
  292.         BotRtRow = UpLtRow+5
  293.     Else
  294.         Return()
  295.     EndIf
  296.     CalcBox(Off)            // close the calc window
  297.     ShadowBox(Off)        // erase the shadow
  298.     ShadowBox(On)            // redraw the shadow
  299.     CalcBox(On)                // redraw the window
  300.     UpdateField()            // refill the fields
  301. End MoveBox
  302. /*********************** Temporary help display ***************************/
  303. Proc CalcHelp()      // minimum help.
  304.  
  305.     Integer
  306.         OldAttr = Set(Attr,Query(MenuTextAttr))
  307.  
  308.     HelpFlag = True  // let GetInput know to trap keys entered here.
  309.     PopWinOpen(1,1,42,21,1,'Help',Query(MenuBorderAttr))
  310.     VgotoXY(1,1)
  311.     ClrScr()
  312. /* Put help text in help box */
  313.     VgotoXY(1,2)
  314.     PutLine('Active function keys are hi-lighted',40)
  315.   VgotoXY(1,4)
  316.     PutLine('Base Toggles:',40)
  317.     VgotoXY(1,5)
  318.     PutLine('Hex,  W: Binary,  Octal,  T: Decimal',40)
  319.     VgotoXY(1,7)
  320.     PutLine('Editing:',40)
  321.     VgotoXY(1,8)
  322.     PutLine('Backspace: Delete entry Rt to Lt.',40)
  323.     VgotoXY(1,9)
  324.     PutLine('Delete: Clear entry',40)
  325.     VgotoXY(1,11)
  326.     PutLine('Math:',40)
  327.     VgotoXY(1,12)
  328.     PutLine('< Shl  > Shr  & And  | Or  ^ Xor  \ Mod',40)
  329.     VgotoXY(1,13)
  330.     PutLine('+ Add  - Subtract  * Multiply  / Divide',40)
  331.     VgotoXY(1,14)
  332.     PutLine('Not',40)
  333.     VgotoXY(1,16)
  334.     PutLine('Other:',40)
  335.     VgotoXY(1,17)
  336.     PutLine('Get number under cursor into Field',40)
  337.     VgotoXY(1,18)
  338.     PutLine('Paste Field into Current edit buffer',40)
  339.     VgotoXY(1,19)
  340.     PutLine('Word size [0FEDCBA987654321] (0=10h)',40)
  341. /* Highlight the hotkeys */
  342.     VGotoXY(3,5)
  343.     PutAttr(Query(MenuTextLtrAttr),1)  // hex
  344.     VGotoXY(7,5)
  345.     PutAttr(Query(MenuTextLtrAttr),1)  // binary
  346.     VGotoXY(19,5)
  347.     PutAttr(Query(MenuTextLtrAttr),1)  // octal
  348.     VGotoXY(27,5)
  349.     PutAttr(Query(MenuTextLtrAttr),1)  // decimal
  350.     VGotoXY(1,8)
  351.     PutAttr(Query(MenuTextLtrAttr),9)  // backspace
  352.     VGotoXY(1,9)
  353.     PutAttr(Query(MenuTextLtrAttr),6)  // delete
  354.     VGotoXY(1,12)
  355.     PutAttr(Query(MenuTextLtrAttr),1)  // <
  356.     VGotoXY(8,12)
  357.     PutAttr(Query(MenuTextLtrAttr),1)  // >
  358.     VGotoXY(15,12)
  359.     PutAttr(Query(MenuTextLtrAttr),1)  // &
  360.     VGotoXY(22,12)
  361.     PutAttr(Query(MenuTextLtrAttr),1)  // |
  362.     VGotoXY(28,12)
  363.     PutAttr(Query(MenuTextLtrAttr),1)  // ^
  364.     VGotoXY(35,12)
  365.     PutAttr(Query(MenuTextLtrAttr),1)  // Not
  366.     VGotoXY(1,13)
  367.     PutAttr(Query(MenuTextLtrAttr),1)  // +
  368.     VGotoXY(8,13)
  369.     PutAttr(Query(MenuTextLtrAttr),1)  // -
  370.     VGotoXY(20,13)
  371.     PutAttr(Query(MenuTextLtrAttr),1)  // *
  372.     VGotoXY(32,13)
  373.     PutAttr(Query(MenuTextLtrAttr),1)  // '/'
  374.     VGotoXY(1,14)
  375.     PutAttr(Query(MenuTextLtrAttr),1)  // MOD
  376.     VGotoXY(1,17)
  377.     PutAttr(Query(MenuTextLtrAttr),1)  // Get
  378.     VGotoXY(1,18)
  379.     PutAttr(Query(MenuTextLtrAttr),1)  // Paste
  380.     VGotoXY(3,19)
  381.     PutAttr(Query(MenuTextLtrAttr),1)  // WordSize
  382. /* wait for key before exiting */
  383.     Repeat until keypressed()          // keep waiting for a keypress
  384.     Set(Attr,OldAttr)                 // restore previous attr
  385.     PopWinClose()              // close up the box
  386. End CalcHelp
  387. /*********************** Get and display input ****************************/
  388. Proc ShowInput(String tmp) // ShowInput only used by GetInput()
  389.  
  390.     String    InputTest[MaxField]  = '', // copy of input string
  391.                     s[1] = UpCase(tmp)      // force a..f upper case for overflow compare
  392.  
  393.     If New
  394.         ClrField()          // if NEW entry clear field
  395.         InPut = s         // set Input to first char
  396.         New = False         // after first key no longer 'New'
  397.     // check for string length and overflow
  398.     Elseif Length(Input) <= Length(Str(MaxInt,Base)) and Length(Input) < MaxField-1
  399.         InputTest = Input + s// string for compare
  400.         While InputTest[1] == '0' and Length(InputTest) > 1  // no leading zeros
  401.             InputTest = SubStr(InputTest,2,Length(InputTest)) // strip leading 0s
  402.         EndWhile
  403.         If InputTest <> Str(Val(Input+s,base),base)  // if overflow strings won't match
  404.             Overflow()      // show error message
  405.         Else
  406.             Input = Input+s  // all is well add new digit on tail
  407.         EndIf
  408.     EndIf
  409.     X = Val(Input,Base)      // accumulate Real Input
  410.     Vgotoxy(FieldX,FieldY)  // goto field
  411.     PutLine(Format(Input:MaxField-1),MaxField-1)  // write the entered data
  412. End ShowInput
  413. //---------------------------
  414. Proc SetOpFlags()
  415.     Y = X
  416.     New = True            // ready for next entry
  417. End SetOpFlags
  418. //---------------------------
  419. Proc GetInput()        // get keyboard input and display it
  420.  
  421.     Integer
  422.         Key,                    // key character value
  423.         NumKey,                // number value of key
  424.         i                            // scratch counter
  425.  
  426. Loop             // you're in the loop now, only one way out...
  427.     Repeat until Keypressed()  // keep cycling while waiting for keys
  428.     Key = GetKey()          // get value
  429.     NumKey = Key & 0FFh  // character value of key (or 0 for numpad or 224 for greykeys)
  430.     If HelpFlag              // trap key used to exit help
  431.         Key = 255          // set key to unused value
  432.         NumKey = 0             // set key to unused value
  433.         HelpFlag = False         // ready to accept values or commands
  434.     EndIf
  435.  
  436.     case NumKey              /***** MAIN INPUT *****/
  437.      /***** NUMBER INPUT '0'..'9',A..F,a..f *****/
  438.  
  439.         When 030h..039h,041h..046h,061h..066h  // test if in 'all numbers set'
  440.           If Base == 16                  // HEX accepts [0..9,a..f,A..F]
  441.                  ShowInput(Chr(NumKey))          // display keyed number
  442.             ElseIf Base == 10                 // DEC accepts [0..9]
  443.                  Case NumKey
  444.                   When 030h..039h
  445.                          ShowInput(Chr(NumKey))      // display keyed number
  446.                  EndCase                  // fall through if not 0..9
  447.           ElseIf Base == 8              // OCT accepts [0..7]
  448.                  Case NumKey
  449.                   When 030h..037h
  450.                          ShowInput(Chr(NumKey))      // display keyed number
  451.                  EndCase                  // fall through if not 0..7
  452.             ElseIf Base == 2              // BIN accepts [0,1]
  453.                 Case NumKey
  454.                   When 030h..031h
  455.                          ShowInput(Chr(NumKey))      // display keyed number
  456.                      EndCase                  // fall through if not 0..7
  457.           EndIf
  458.  
  459.         When 08h              /***** BACKSPACE *****/
  460.             If New InPut = '' EndIf
  461.             Input = SubStr(Input,1,Length(Input)-1)  // remove last char.
  462.           If Length(Input) > 0     // as long as it has a length, 'Input'
  463.                  X = Val(Input,Base)  //  still has a value, update accumulator.
  464.           Else
  465.                  X = 0             // otherwise zero the accumulator
  466.             EndIf
  467.             ClrField()          // clear the display
  468.             Vgotoxy(FieldX,FieldY)
  469.           PutLine(Format(X:MaxField-1:' ':Base,BaseLtr:1),MaxField)  // display
  470.  
  471.         When 02Bh          /****** ADD *****/
  472.             SetOpFlags()
  473.             Add = True
  474.         When 02Dh          /****** SUBTRACT *****/
  475.             SetOpFlags()
  476.             Subtract = True
  477.         When 02Ah          /***** MULTIPLY *****/
  478.             SetOpFlags()
  479.             Multiply = True
  480.         When 02Fh          /****** DIVIDE *****/
  481.             SetOpFlags()
  482.             Divide = True
  483.         When 05Ch          /****** MODULO *****/
  484.             SetOpFlags()
  485.             Modulo = True
  486.         When 026h          /****** Bitwise AND *****/
  487.             SetOpFlags()
  488.             AndFlag = True
  489.         When 07Ch          /****** Bitwise OR *****/
  490.             SetOpFlags()
  491.             OrFlag = True
  492.         When 05Eh          /****** Bitwise XOR *****/
  493.             SetOpFlags()
  494.             XorFlag = True
  495.         When 06Eh, 04Eh      /****** Bitwise NOT *****/
  496.             NotFlag = True
  497.             DoMath()      // do it now - does not affect any process in progress
  498.         When 03Eh, 02Eh      /****** SHR *****/
  499.             SetOpFlags()
  500.             ShftRt = True
  501.         When 03Ch, 02Ch      /****** SHL *****/
  502.             SetOpFlags()
  503.             ShftLt = True
  504.         When 03Dh,0Dh  // <=> or <GreyEnter> keys
  505.             DoMath()
  506.             New = True
  507.                 /****** SPECIAL KEYS *****/
  508.         When 0, 224          // when number pad arrows or grey arrows
  509.           Case Key shr 8      // test key for extended values
  510.                  When 83         // del
  511.                     X = 0
  512.                     New = True
  513.                     UpdateField()  // clear current entry
  514.                 When 115          // ctrl left
  515.                     MoveBox(-1,0)  //      move box left
  516.                 When 116          // ctrl right
  517.                     MoveBox(1,0)     //      move box right
  518.                 When 141          // ctrl up
  519.                     MoveBox(0,-1)  //      move box up
  520.                 When 145          // ctrl dn
  521.                     MoveBox(0,1)     //      move box dn
  522.             EndCase
  523.                 /****** LETTER KEYS *****/
  524.         When 057h, 077h      // 'W','w' = binary
  525.             BinHexDecOct(2)
  526.         When 04Fh, 06Fh      // 'O','o' = Octal
  527.             BinHexDecOct(8)
  528.         When 054h, 074h      // 'T','t' = Decimal
  529.             BinHexDecOct(10)
  530.         When 058h, 078h      // 'x','X' = HexiDecimal
  531.             BinHexDecOct(16)
  532.         When 048h, 068h      // 'H' or 'h' calls help
  533.             CalcHelp()
  534.         When 047h, 067h      // 'G' or 'g' get number
  535.             If GetStr == ''
  536.                  // do nothing
  537.             Else
  538.                 X = Val(GetStr,base)
  539.                 UpDateField()
  540.             EndIf
  541.         When 050h, 070h      // 'P' or 'p' Paste X into buffer
  542.             i = 1
  543.             GetStr = Format(x:MaxField-1:' ':Base)
  544.             While GetStr[i] == chr(32) and i < MaxField
  545.                 i = i + 1
  546.             EndWhile
  547.             GetStr = SubStr(GetStr,i,Length(GetStr)) // trim leading spaces
  548.             InsertText(' '+GetStr+' ') // paste into text bracketed with spaces
  549.             New = True        // assure that next entry is NEW
  550.             break
  551.         When 72h,52h        // set wordsize
  552.             SetWordSize()
  553.                  /****** ESCAPE KEY *****/
  554.         When 01Bh            // Esc pressed, time to quit
  555.             Y = X                // update
  556.             New = True    // assure that next entry is NEW
  557.             Break                // exit loop return to edit
  558.         EndCase
  559. EndLoop                        // End entry loop - back to start
  560. End GetInput
  561. /******************************** MAIN ************************************/
  562.  
  563. Proc Main()                        // Startup code ACalc.s
  564.     If Not InitFlag            // if first use,
  565.         InitRegs()                // inititilize vars, otherwise retain previous values
  566.     EndIf
  567.     // Mark current word for import
  568.     If IsBlockMarked() PushBlock() EndIf        // save existing block marks
  569.     If MarkWord()                                                        // a word was markable
  570.         GetStr = GetMarkedText()                            // grab it
  571.         UnMarkBlock()                                                    // unmark word
  572.     Else
  573.         GetStr = ''                             // set string to nil on failure
  574.     EndIf
  575.     If GetStr <> '' PopBlock() EndIf           // restore previous marking
  576.   // end get import string
  577.     UpDateDisplay()            // clean up any editor messages left onscreen
  578.     Set(Cursor,Off)            // turn off cursor since it intrudes if under box
  579.     ShadowBox(On)                // draw the shadow
  580.     CalcBox(On)                    // draw the window
  581.     UpdateField()                // fill the fields
  582.     GetInput()                    // enter Input loop
  583.     CalcBox(Off)                // close the calc window
  584.     ShadowBox(Off)            // erase the shadow
  585.     Set(Cursor,On)            // done - turn cursor back on
  586. End Main                            // Acalc.s
  587.  
  588. /**************************** EOF 'acalc.s'*********************************/
  589.  
  590. // <Ctrl centercursor>     ExecMacro('acalc')   // my calc button
  591.