home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / BCALCS.ZIP / BIGPRINT.C < prev    next >
C/C++ Source or Header  |  1989-02-04  |  32KB  |  1,188 lines

  1. /*
  2.  *    **************************************************
  3.  *    *                                                *
  4.  *    *                  BIGPRINT.C                    *
  5.  *    *                                                *
  6.  *    *          Extended Precision Calculator         *
  7.  *    *                                                *
  8.  *    *               Printing Routines                *
  9.  *    *                                                *
  10.  *    *              Version 4.3 02-04-89              *
  11.  *    *                                                *
  12.  *    *              Judson D. McClendon               *
  13.  *    *              329 37th Court N.E.               *
  14.  *    *              Birmingham, AL 35215              *
  15.  *    *                 205-853-8440                   *
  16.  *    *            Compuserve [74415,1003]             *
  17.  *    *                                                *
  18.  *    **************************************************
  19.  */
  20.  
  21.  
  22.  
  23. /*
  24.  *    **************************************************
  25.  *    *                                                *
  26.  *    *                   Includes                     *
  27.  *    *                                                *
  28.  *    **************************************************
  29.  */
  30.  
  31. #include <ctype.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include "bigcalc.h"
  36. #include "biggvar.h"
  37.  
  38.  
  39.  
  40.  
  41.  
  42. /*
  43.  *    **************************************************
  44.  *    *                                                *
  45.  *    *            Source Local Variables              *
  46.  *    *                                                *
  47.  *    **************************************************
  48.  */
  49.  
  50. static int
  51.    ppos = 0,            /* Current print column */
  52.    prevchr;             /* Previous character printed */
  53.  
  54.  
  55.  
  56.  
  57.  
  58. /*
  59.  *    **************************************************
  60.  *    *                                                *
  61.  *    *               Printing routines                *
  62.  *    *                                                *
  63.  *    **************************************************
  64.  */
  65.  
  66.  
  67. /*
  68.  *    **************************************************
  69.  *    *                                                *
  70.  *    *                 Print Heading                  *
  71.  *    *                                                *
  72.  *    **************************************************
  73.  */
  74.  
  75. extern void PrintHeading(void)
  76.  
  77. {
  78.  
  79.    Message("Printing...");
  80.  
  81.    PString("\r\n***  BIGCALC  (precision ");
  82.    PInteger((long) normprec);
  83.    PString(" digits, ");
  84.    PChar(PRINTDECIMAL);
  85.    PString(" is decimal point)  ***\r\n\n");
  86.  
  87. }
  88.  
  89.  
  90.  
  91.  
  92. /*
  93.  *    **************************************************
  94.  *    *                                                *
  95.  *    *     Print Registers [lo to hi] on Printer      *
  96.  *    *                                                *
  97.  *    **************************************************
  98.  */
  99.  
  100. extern void PrintReg(int lo, int hi)
  101.  
  102. {
  103.  
  104.    int r;
  105.  
  106.    for (r = lo; r <= hi; r++) {
  107.       PChar(r + '0');
  108.       PrintNumber(®[r]);
  109.       NewLine();
  110.       }
  111.  
  112.    NewLine();
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119. /*
  120.  *    **************************************************
  121.  *    *                                                *
  122.  *    *       Print Stack [lo to hi] on Printer        *
  123.  *    *                                                *
  124.  *    **************************************************
  125.  */
  126.  
  127. extern void PrintStack(int lo, int hi)
  128.  
  129. {
  130.  
  131.    int s;
  132.  
  133.    for (s = hi; s >= lo; s--) {
  134.       PChar(stackname[s]);
  135.       PrintNumber(&stack[s]);
  136.       NewLine();
  137.       }
  138.  
  139.    NewLine();
  140.  
  141. }
  142.  
  143.  
  144.  
  145.  
  146. /*
  147.  *    **************************************************
  148.  *    *                                                *
  149.  *    *   Display Memory Register in Full on Screen    *
  150.  *    *                                                *
  151.  *    **************************************************
  152.  */
  153.  
  154. extern void DisplayReg(int r)
  155.  
  156. {
  157.  
  158.    printtoscreen = TRUE;      /* Temporarily print to screen */
  159.  
  160.    CurPos(1, 1);
  161.    EraEop();
  162.    menucleared = TRUE;
  163.  
  164.    PChar(r + '0');
  165.    PrintNumber(®[r]);
  166.  
  167.    MessageWait("");
  168.  
  169.    WorkScreen();
  170.  
  171.    printtoscreen = FALSE;     /* Reset print to screen */
  172.  
  173. }
  174.  
  175.  
  176.  
  177.  
  178. /*
  179.  *    **************************************************
  180.  *    *                                                *
  181.  *    *    Display Stack Register in Full on Screen    *
  182.  *    *                                                *
  183.  *    **************************************************
  184.  */
  185.  
  186. extern void DisplayStack(int s)
  187.  
  188. {
  189.  
  190.    printtoscreen = TRUE;      /* Temporarily print to screen */
  191.  
  192.    CurPos(1, 1);
  193.    EraEop();
  194.    menucleared = TRUE;
  195.  
  196.    PChar(stackname[s]);
  197.    PrintNumber(&stack[s]);
  198.  
  199.    MessageWait("");
  200.  
  201.    WorkScreen();
  202.  
  203.    printtoscreen = FALSE;     /* Reset print to screen */
  204.  
  205. }
  206.  
  207.  
  208.  
  209.  
  210. /*
  211.  *    **************************************************
  212.  *    *                                                *
  213.  *    *       Print Number [*number] on Printer        *
  214.  *    *                                                *
  215.  *    **************************************************
  216.  */
  217.  
  218. extern void PrintNumber(NORMTYPE *nbr)
  219.  
  220. {
  221.  
  222.    long exponent;
  223.    int i, digits, chrcount;
  224.  
  225.    prevchr = '0';
  226.  
  227.    PString(": ");
  228.    ppos = SIGNPRTCOL;
  229.  
  230.    chrcount = 0;
  231.    digits = nbr->digits;
  232.    exponent = nbr->exp;
  233.  
  234.    if (nbr->digits == 0) {
  235.       PString(" 0\r\n\n");
  236.       return;
  237.       }
  238.  
  239.  
  240.    if ( (scinotation)
  241.          ||
  242.         (exponent < minfloatprn)
  243.          ||
  244.         (exponent > maxfloatprn) )
  245.  
  246.       {                             /* Scientific Notation */
  247.  
  248.       for (i = 1; i < groupsize; i++)
  249.          PCharWrap(' ');
  250.  
  251.       PSign(nbr->sign);                   /* Print sign */
  252.  
  253.       PCharWrap(nbr->man[0]+ '0');        /* First digit and decimal point */
  254.       PCharWrap(PRINTDECIMAL);
  255.  
  256.       if (digits <= 1)                    /* If no more digits, */
  257.          PCharWrap('0');                  /*  print one zero    */
  258.       else {
  259.          for (i = 1; i < digits; i++) {   /*  print remaining digits */
  260.             PCharWrap(nbr->man[i]+ '0');
  261.             if (! (i % groupsize))
  262.                PCharWrap(' ');
  263.             }
  264.          }
  265.       PExponent(nbr->exp - 1L);           /* Print exponent */
  266.  
  267.       }                             /* Scientific Notation end */
  268.  
  269.    else
  270.  
  271.  
  272.       {                             /* Floating Decimal */
  273.  
  274.       if (exponent <= 0L)
  275.  
  276.          {                                /* Number < 1 */
  277.  
  278.          for (i = 1; i < groupsize; i++)
  279.             PCharWrap(' ');
  280.  
  281.          PSign(nbr->sign);                   /* Print sign */
  282.          PCharWrap('0');                     /* Zero left of decimal looks good */
  283.          PCharWrap(PRINTDECIMAL);            /* Decimal point */
  284.  
  285.          for (i = 0; i > (int)exponent; i--) {  /* Zeros to left of number */
  286.             PCharWrap('0');
  287.             if (! (++chrcount % groupsize))
  288.                PCharWrap(' ');
  289.             }
  290.  
  291.          for (i = 0; i < digits; i++) {      /* Print mantissa digits */
  292.             PCharWrap(nbr->man[i] + '0');
  293.             if (! (++chrcount % groupsize))
  294.                PCharWrap(' ');
  295.             }
  296.          }                                /* Number < 1 */
  297.  
  298.       else
  299.  
  300.  
  301.          {                                /* Number >= 1 */
  302.  
  303.                                              /* Calculate digit allignment   */
  304.          i = (int)((3000000L - exponent) % (long)groupsize);
  305.          while (i-- > 0)                     /*  here 1 <= exponent <= maxfloatprn */
  306.             PCharWrap(' ');
  307.  
  308.          PSign(nbr->sign);                   /* Print sign */
  309.  
  310.          chrcount = (int)exponent;           /* Distance from decimal point to    */
  311.                                              /*  print groups of groupsize digits */
  312.  
  313.          for (i = 0; i < (int)exponent; i++) {  /* Digits to left of decimal */
  314.             if (i < digits)
  315.                PCharWrap(nbr->man[i] + '0'); /* Mantissa digits while they last */
  316.             else
  317.                PCharWrap('0');               /* Zeros if mantissa exhausted */
  318.  
  319.             if (! (--chrcount % groupsize))  /* Space between groups */
  320.                if (chrcount)                 /*  of groupsize digits */
  321.                   PCharWrap(' ');
  322.             }
  323.  
  324.          chrcount = 0;                       /* Distance from decimal */
  325.  
  326.          if (i < digits) {                   /* If digits to right of decimal */
  327.             PCharWrap(PRINTDECIMAL);         /*  print decimal point          */
  328.  
  329.             for (i = (int)exponent; i < digits; i++) {   /* digits to right of decimal */
  330.                PCharWrap(nbr->man[i] + '0');
  331.                if (! (++chrcount % groupsize))
  332.                   PCharWrap(' ');
  333.                }
  334.             }
  335.  
  336.          }                                /* Number >= 1 */
  337.  
  338.       }                             /* Floating Decimal */
  339.  
  340.    NewLine();
  341.  
  342. }
  343.  
  344.  
  345.  
  346.  
  347.  
  348. /*
  349.  *    **************************************************
  350.  *    *                                                *
  351.  *    *         Print Char & Wrap Print Line           *
  352.  *    *                                                *
  353.  *    **************************************************
  354.  */
  355.  
  356. static void PCharWrap(int chr)
  357.  
  358. {
  359.  
  360.    int col;
  361.  
  362.    if ( (ppos > MAXPRTCOL)
  363.          &&
  364.         (chr != ' ')
  365.          &&
  366.         ( (prevchr == ' ')
  367.            ||
  368.           (prevchr == PRINTDECIMAL) ) ) {
  369.       PString("\r\n");
  370.       for (col = 1; col < MINPRTCOL; col++)
  371.          PChar(' ');
  372.       ppos = MINPRTCOL;
  373.       }
  374.  
  375.    PChar(chr);
  376.    ppos++;
  377.    prevchr = chr;
  378.  
  379. }
  380.  
  381.  
  382.  
  383.  
  384. /*
  385.  *    **************************************************
  386.  *    *                                                *
  387.  *    *              Print Sign Character              *
  388.  *    *                                                *
  389.  *    **************************************************
  390.  */
  391.  
  392. static void PSign(int sign)
  393.  
  394. {
  395.  
  396.    if (sign == '-')
  397.       PCharWrap('-');
  398.    else
  399.       PCharWrap(' ');
  400.  
  401. }
  402.  
  403.  
  404.  
  405.  
  406. /*
  407.  *    **************************************************
  408.  *    *                                                *
  409.  *    *            Print Exponent on Printer           *
  410.  *    *                                                *
  411.  *    **************************************************
  412.  */
  413.  
  414. static void PExponent(long exponent)
  415.  
  416. {
  417.  
  418.    if (prevchr != ' ')
  419.       PChar(' ');
  420.    PChar('e');
  421.    PInteger(exponent);
  422.  
  423. }
  424.  
  425.  
  426.  
  427.  
  428.  
  429. /*
  430.  *    **************************************************
  431.  *    *                                                *
  432.  *    *               Writing routines                 *
  433.  *    *                                                *
  434.  *    **************************************************
  435.  */
  436.  
  437.  
  438.  
  439. /*
  440.  *    **************************************************
  441.  *    *                                                *
  442.  *    *          Write Registers [lo to hi]            *
  443.  *    *                                                *
  444.  *    **************************************************
  445.  */
  446.  
  447. extern void WriteReg(int lo, int hi)
  448.  
  449. {
  450.  
  451.    int r;
  452.  
  453.    for (r = lo; r <= hi; r++) {
  454.       CurPos(r + 4, SIGNDISPCOL);
  455.       WriteNumber(®[r]);
  456.       }
  457.  
  458. }
  459.  
  460.  
  461.  
  462.  
  463. /*
  464.  *    **************************************************
  465.  *    *                                                *
  466.  *    *            Write Stack [lo to hi]              *
  467.  *    *                                                *
  468.  *    **************************************************
  469.  */
  470.  
  471. extern void WriteStack(int lo, int hi)
  472.  
  473. {
  474.  
  475.    int s;
  476.  
  477.    for (s = hi; s >= lo; s--) {
  478.       CurPos(XSIGNROW - s, SIGNDISPCOL);
  479.       WriteNumber(&stack[s]);
  480.       }
  481.  
  482. }
  483.  
  484.  
  485.  
  486.  
  487. /*
  488.  *    **************************************************
  489.  *    *                                                *
  490.  *    *        Write Number [*number] on Screen        *
  491.  *    *                                                *
  492.  *    **************************************************
  493.  */
  494.  
  495. extern void WriteNumber(NORMTYPE *nbr)
  496.  
  497. {
  498.    long exponent;
  499.    int i, digits;
  500.  
  501.    EraEol();
  502.  
  503.    if (nbr->digits == 0) {
  504.       WString(" 0");
  505.       return;
  506.       }
  507.  
  508.    if (nbr->sign == '-')
  509.       WChar('-');
  510.    else
  511.       WChar(' ');
  512.    ppos = MINDISPCOL;
  513.  
  514.    digits = nbr->digits;
  515.    exponent = nbr->exp;
  516.  
  517.    if ( (scinotation)
  518.          ||
  519.         (exponent < MINFLOATDSP)
  520.          ||
  521.         (exponent > MAXFLOATDSP)
  522.          ||
  523.         (exponent > normprec) )
  524.  
  525.       {                             /* Scientific Notation */
  526.  
  527.       WChar(nbr->man[0]+ '0');         /* First digit and decimal point */
  528.       WChar(DISPDECIMAL);
  529.       ppos += 2;
  530.  
  531.       if (digits <= 1) {                  /* If no more digits, */
  532.          WChar('0');                      /*  print one zero    */
  533.          ppos++;
  534.          }
  535.       else
  536.          for (i = 1; i < digits; i++) {   /*  print remaining digits */
  537.             WChar(nbr->man[i]+ '0');
  538.             if (++ppos >= MAXDISPCOL)
  539.                break;
  540.             }
  541.       WExponent(nbr->exp - 1L);           /* Write exponent */
  542.  
  543.       }                             /* Scientific Notation end */
  544.  
  545.    else
  546.  
  547.       {                             /* Floating Decimal */
  548.       if (exponent <= 0L)
  549.  
  550.          {                             /* Number < 1 */
  551.  
  552.          WChar(DISPDECIMAL);                 /* Decimal point */
  553.          ppos++;
  554.  
  555.          for (i = 0; i > (int)exponent; i--) {  /* Zeros to left of number */
  556.             WChar('0');
  557.             ppos++;
  558.             }
  559.  
  560.          for (i = 0; i < digits; i++) {      /* Write number digits */
  561.             WChar(nbr->man[i] + '0');
  562.             if (++ppos > 79)                 /* Until end of digits or line */
  563.                break;
  564.             }
  565.          }                             /* Number < 1 end */
  566.  
  567.       else
  568.  
  569.          {                             /* Number >= 1 */
  570.  
  571.          for (i = 0; i < (int)exponent; i++) {  /* Digits to left of decimal */
  572.             if (i < digits)
  573.                WChar(nbr->man[i] + '0');  /* Mantissa digits while they last */
  574.             else
  575.                WChar('0');                /* Zeros if mantissa exhausted */
  576.             ppos++;
  577.             }
  578.  
  579.          if (i < digits) {                /* Write digits to right of decimal */
  580.             WChar(DISPDECIMAL);
  581.             ppos++;
  582.             for (i = (int)exponent; i < digits; i++) {
  583.                WChar(nbr->man[i] + '0');
  584.                if (++ppos > 79)
  585.                   break;
  586.                }
  587.             }
  588.          }                             /* Number >= 1 end */
  589.  
  590.       }                             /* Floating Decimal end */
  591.  
  592. }
  593.  
  594.  
  595.  
  596.  
  597. /*
  598.  *    **************************************************
  599.  *    *                                                *
  600.  *    *            Write Exponent on Screen            *
  601.  *    *                                                *
  602.  *    **************************************************
  603.  */
  604.  
  605. static void WExponent(long exponent)
  606.  
  607. {
  608.  
  609.    WString(" e");
  610.    WInteger(exponent);
  611.  
  612. }
  613.  
  614.  
  615.  
  616.  
  617. /*
  618.  *    **************************************************
  619.  *    *                                                *
  620.  *    *             Get Prompted Character             *
  621.  *    *                                                *
  622.  *    **************************************************
  623.  */
  624.  
  625. extern int GetPrompt(void)
  626.  
  627. {
  628.  
  629.    if (menucleared) {            /* Restore menu if cleared */
  630.       OnScreenMenu();
  631.       menucleared = FALSE;
  632.       }
  633.  
  634.    if (charpresent) {            /* Character passed from routine */
  635.       charpresent = FALSE;
  636.       return(chr);
  637.       }
  638.    else {                        /* Get character */
  639.       Message("(Esc to Exit)");
  640.       return(GetChar());
  641.       }
  642.  
  643. }
  644.  
  645.  
  646.  
  647.  
  648. /*
  649.  *    **************************************************
  650.  *    *                                                *
  651.  *    *                Overflow Message                *
  652.  *    *                                                *
  653.  *    **************************************************
  654.  */
  655.  
  656. extern void Overflow(void)
  657.  
  658. {
  659.  
  660.    Beep();
  661.    MessageWait("** Overflow **");
  662.  
  663. }
  664.  
  665.  
  666.  
  667.  
  668. /*
  669.  *    **************************************************
  670.  *    *                                                *
  671.  *    *             Divide By Zero Message             *
  672.  *    *                                                *
  673.  *    **************************************************
  674.  */
  675.  
  676. extern void DivideByZero(void)
  677.  
  678. {
  679.  
  680.    Beep();
  681.    MessageWait("** Divide by zero **");
  682.  
  683. }
  684.  
  685.  
  686.  
  687.  
  688. /*
  689.  *    **************************************************
  690.  *    *                                                *
  691.  *    *              Zero Argument Message             *
  692.  *    *                                                *
  693.  *    **************************************************
  694.  */
  695.  
  696. extern void ZeroArgument(void)
  697.  
  698. {
  699.  
  700.    Beep();
  701.    MessageWait("** Zero Argument **");
  702.  
  703. }
  704.  
  705.  
  706.  
  707.  
  708. /*
  709.  *    **************************************************
  710.  *    *                                                *
  711.  *    *            Negative Argument Message           *
  712.  *    *                                                *
  713.  *    **************************************************
  714.  */
  715.  
  716. extern void NegativeArgument(void)
  717.  
  718. {
  719.  
  720.    Beep();
  721.    MessageWait("** Negative Argument **");
  722.  
  723. }
  724.  
  725.  
  726.  
  727.  
  728. /*
  729.  *    **************************************************
  730.  *    *                                                *
  731.  *    *          Argument not Integer Message          *
  732.  *    *                                                *
  733.  *    **************************************************
  734.  */
  735.  
  736. extern void ArgumentNotInteger(void)
  737.  
  738. {
  739.  
  740.    Beep();
  741.    MessageWait("** Argument not Integer **");
  742.  
  743. }
  744.  
  745.  
  746.  
  747.  
  748. /*
  749.  *    **************************************************
  750.  *    *                                                *
  751.  *    *                Argument Invalid                *
  752.  *    *                                                *
  753.  *    **************************************************
  754.  */
  755.  
  756. extern void ArgumentInvalid(void)
  757.  
  758. {
  759.  
  760.    Beep();
  761.    MessageWait("** Argument Invalid **");
  762.  
  763. }
  764.  
  765.  
  766.  
  767.  
  768. /*
  769.  *    **************************************************
  770.  *    *                                                *
  771.  *    *          Insufficient Memory Message           *
  772.  *    *                                                *
  773.  *    **************************************************
  774.  */
  775.  
  776. extern void MemoryError(void)
  777.  
  778. {
  779.  
  780.    Beep();
  781.    MessageWait("** Insufficient Memory **");
  782.  
  783. }
  784.  
  785.  
  786.  
  787.  
  788. /*
  789.  *    **************************************************
  790.  *    *                                                *
  791.  *    *                Screen Routines                 *
  792.  *    *                                                *
  793.  *    **************************************************
  794.  */
  795.  
  796.  
  797.  
  798.  
  799. /*
  800.  *    **************************************************
  801.  *    *                                                *
  802.  *    *                On Screen Menu                  *
  803.  *    *                                                *
  804.  *    **************************************************
  805.  */
  806.  
  807. extern void OnScreenMenu(void)
  808.  
  809. {
  810.  
  811.    CurPos(19, 1);
  812.    EraEop();
  813.    WriteAt(20, 1, "0-9.E  Number   + >Add        X >Xchg X R   V >View full");
  814.    WriteAt(21, 1, "    S  ChgSign  - >Sub   Lft/Rt >Xchg X Y   F >Float/Sci");
  815.    WriteAt(22, 1, "BkSpc  Clear X  * >Mul   Up/Dwn >Roll UpDn  G >Group 3/5");
  816.    WriteAt(23, 1, "Enter >Enter    / >Div     PgUp >Store      P >Print");
  817.    WriteAt(24, 1, "    L >Last X   C >Clear   PgDn >Recall     D >Disk/Print");
  818.  
  819.    WriteAt(19, 58, "(M rotates Fn key menu)");
  820.  
  821.    if (! menunbr) {
  822.       WriteAt(20, 61, "F1 >Help  F2 >Y^X");
  823.       WriteAt(21, 61, "F3 >√X    F4 >X²");
  824.       WriteAt(22, 61, "F5 >1/X   F6 >X!");
  825.       WriteAt(23, 61, "F7 >INT   F8 >FRAC");
  826.       WriteAt(24, 61, "F9 >π     F0 >e");
  827.       }
  828.    else {
  829.       WriteAt(20, 60, "^F1 >sinX ^F2 >asinX");
  830.       WriteAt(21, 60, "^F3 >cosX ^F4 >acosX");
  831.       WriteAt(22, 60, "^F5 >tanX ^F6 >atanX");
  832.       WriteAt(23, 60, "^F7 >logX ^F8 >10^X");
  833.       WriteAt(24, 60, "^F9 >lnx  ^F0 >e^X");
  834.       }
  835.  
  836. }
  837.  
  838.  
  839.  
  840.  
  841. /*
  842.  *    **************************************************
  843.  *    *                                                *
  844.  *    *                Initial Screen                  *
  845.  *    *                                                *
  846.  *    **************************************************
  847.  */
  848.  
  849. extern void InitialScreen(void)
  850.  
  851. {
  852.  
  853.    HelpScreen1();
  854.    MessageWait("");
  855.  
  856.    WorkScreen();
  857.  
  858. }
  859.  
  860.  
  861.  
  862.  
  863. /*
  864.  *    **************************************************
  865.  *    *                                                *
  866.  *    *                  Help Screen                   *
  867.  *    *                                                *
  868.  *    **************************************************
  869.  */
  870.  
  871. extern void HelpScreen(void)
  872.  
  873. {
  874.  
  875.    int screen;
  876.  
  877.    menucleared = TRUE;
  878.  
  879.    screen = 2;
  880.  
  881.    do {
  882.       switch (screen) {
  883.          case (1):
  884.             HelpScreen1();
  885.             break;
  886.          case (2):
  887.             HelpScreen2();
  888.             break;
  889.          case (3):
  890.             HelpScreen3();
  891.             break;
  892.          }  /* switch */
  893.  
  894.       Message("(Press +=Next page, -=Prev page, Esc=Exit to BIGCALC)");
  895.  
  896.       while (TRUE) {
  897.          chr = GetChar();
  898.          if (chr == '+') {
  899.             if (++screen > 3)
  900.                screen = 1;
  901.             break;
  902.             }
  903.          else if (chr == '-') {
  904.             if (--screen < 1)
  905.                screen = 3;
  906.             break;
  907.             }
  908.          else if (chr == ESCAPE)
  909.             break;
  910.          else
  911.             Beep();
  912.          }  /* while (TRUE) */
  913.  
  914.       } while (chr != ESCAPE);
  915.  
  916.    WorkScreen();
  917.  
  918. }
  919.  
  920.  
  921.  
  922.  
  923. /*
  924.  *    **************************************************
  925.  *    *                                                *
  926.  *    *             Screen Header Line 1               *
  927.  *    *                                                *
  928.  *    **************************************************
  929.  */
  930.  
  931. extern void Heading1(void)
  932.  
  933. {
  934.  
  935.    ScrClr();
  936.    WriteCenter(1, TITLE);
  937.  
  938. }
  939.  
  940.  
  941.  
  942.  
  943. /*
  944.  *    **************************************************
  945.  *    *                                                *
  946.  *    *             Screen Header Line 2               *
  947.  *    *                                                *
  948.  *    **************************************************
  949.  */
  950.  
  951. extern void Heading2(void)
  952.  
  953. {
  954.  
  955.    CurPos(2, 1);
  956.    EraEol();
  957.    WriteAt(2, 8, "Precision is ");
  958.    WInteger((long) normprec);
  959.    WString(" digits,  Digit grouping is ");
  960.    WInteger((long) groupsize);
  961.    WString(",  Print to ");
  962.    WString(printid);
  963.  
  964. }
  965.  
  966.  
  967.  
  968.  
  969. /*
  970.  *    **************************************************
  971.  *    *                                                *
  972.  *    *             Display Help Screen 1              *
  973.  *    *                                                *
  974.  *    **************************************************
  975.  */
  976.  
  977. static void HelpScreen1(void)
  978.  
  979. {
  980.  
  981.    Heading1();
  982.  
  983.    WriteAt( 3,  1, "BIGCALC works like an H-P calculator with stack and ten m"
  984.                    "emory registers.");
  985.    WriteAt( 4,  1, "Maximum precision settable from ");
  986.    WInteger((long)MINPREC);
  987.    WString(" to ");
  988.    WInteger((long)MAXNORM);
  989.    WString(" digits. Exponents to ±");
  990.    WInteger(MAXEXP);
  991.    WString(".");
  992.    WriteAt( 5,  1, "Execute BIGCALC like this:");
  993.  
  994.    WriteAt( 7,  3, "BIGCALC precision   (precision is maximum number of digit"
  995.                    "s, default is ");
  996.    WInteger((long)DEFAULTPREC);
  997.    WString(")");
  998.  
  999.    WriteAt( 9,  1, "BIGCALC has +, -, x, ÷, √X, X², X!, Y^X, logs, trig, pi, "
  1000.                    "e, print, much more.");
  1001.    WriteAt(10,  1, "All trig functions work in radians. BIGCALC is fast, but "
  1002.                    "some operations on");
  1003.    WriteAt(11,  1, "large numbers may take up to several minutes. You can abo"
  1004.                    "rt long calculations");
  1005.    WriteAt(12,  1, "by pressing the Escape key. Press F1 for on-screen help. "
  1006.                    "Registers can be");
  1007.    WriteAt(13,  1, "viewed in full, or printed to printer or disk.");
  1008.  
  1009.    WriteAt(15,  1, "You can specify floating decimal or scientific notation d"
  1010.                    "isplay. Large numbers");
  1011.    WriteAt(16,  1, "display in scientific notation to about 65 digits all the"
  1012.                    " time, but the view");
  1013.    WriteAt(17,  1, "and print commands show full precision in 3 or 5 digit gr"
  1014.                    "oups.");
  1015.  
  1016.    WriteAt(19,  1, " Judson D. McClendon       If you like this program consi"
  1017.                    "der sending a small");
  1018.    WriteAt(20,  1, " 329 37th Court N.E.       contribution to the author. Co"
  1019.                    "mments are welcome.");
  1020.    WriteAt(21,  1, " Birmingham, AL 35215      $20 gets you a disk with the c"
  1021.                    "omplete C source.");
  1022.    WriteAt(22,  1, "     205-853-8440          There is no warranty of any ki"
  1023.                    "nd. The author assumes");
  1024.    WriteAt(23,  1, "Compuserve [74415,1003]    no responsibility for the use "
  1025.                    "of this program.");
  1026.  
  1027. }
  1028.  
  1029.  
  1030.  
  1031.  
  1032. /*
  1033.  *    **************************************************
  1034.  *    *                                                *
  1035.  *    *             Display Help Screen 2              *
  1036.  *    *                                                *
  1037.  *    **************************************************
  1038.  */
  1039.  
  1040. static void HelpScreen2(void)
  1041.  
  1042. {
  1043.  
  1044.    Heading1();
  1045.  
  1046.    WriteAt( 3,  1, "  KEY  FUNCTION     KEY  FUNCTION      "
  1047.                    "KEY  FUNCTION        KEY  FUNCTION");
  1048.  
  1049.    WriteAt( 4, 45, "(M rotates Fn key menu)");
  1050.  
  1051.    WriteAt( 5,  1, "0-9.E  Enter number   V >View number    F1 >Help         "
  1052.                    "   ^F1 >sin X");
  1053.    WriteAt( 6,  1, "    S  change Sign    F >Float/Sci      F2 >Power Y^X    "
  1054.                    "   ^F2 >arcsin X");
  1055.    WriteAt( 7,  1, "BkSpc  CLX/Backspace  G >Group 3/5      F3 >Sq root √x   "
  1056.                    "   ^F3 >cos X");
  1057.    WriteAt( 8,  1, "Enter >Enter          P >Print          F4 >Square X²    "
  1058.                    "   ^F4 >arccos X");
  1059.    WriteAt( 9,  1, "    + >Add Y + X      D >Disk/Print     F5 >Recip 1 ÷ X  "
  1060.                    "   ^F5 >tan X");
  1061.    WriteAt(10,  1, "    - >Sub Y - X   PgUp >Store X        F6 >Fact X!      "
  1062.                    "   ^F6 >arctan X");
  1063.    WriteAt(11,  1, "    * >Mul Y x X   PgDn >Recall X       F7 >Integer XXX. "
  1064.                    "   ^F7 >Common log X");
  1065.    WriteAt(12,  1, "    / >Div Y ÷ X      X >eXchg X & Reg  F8 >Fraction .XXX"
  1066.                    "   ^F8 >Exponent 10^X");
  1067.    WriteAt(13,  1, "    C >Clear      Up/Dn >Roll Up/Dn     F9 >Recall π to X"
  1068.                    "   ^F9 >Natural log X");
  1069.    WriteAt(14,  1, "    L >Last X    Lft/Rt >Exchg X & Y   F10 >Recall e to X"
  1070.                    "  ^F10 >Exponent e^X");
  1071.  
  1072.    WriteAt(16,  5, "To enter a number just begin typing it in. Use Backspace "
  1073.                    "to back up.");
  1074.    WriteAt(17,  5, "To enter an exponent press E then enter the exponent.");
  1075.    WriteAt(18,  5, "Press S while entering mantissa or exponent to change res"
  1076.                    "pective sign.");
  1077.    WriteAt(19,  5, "If you start a number with E a mantissa of 1 is assumed.");
  1078.    WriteAt(20,  5, "Functions marked '>' complete a number being entered befo"
  1079.                    "re acting.");
  1080.    WriteAt(21,  5, "View displays any register to full precision.");
  1081.    WriteAt(22,  5, "Clear, Print, View, Store, Recall & eXchange ask for affe"
  1082.                    "cted register.");
  1083.    WriteAt(23,  5, "BackSpace backs up while entering number, otherwise acts "
  1084.                    "as Clear X.");
  1085.    WriteAt(24,  5, "M rotates function key menus. ^ means control: ^F1 = ctrl"
  1086.                    "-F1");
  1087.  
  1088. }
  1089.  
  1090.  
  1091.  
  1092.  
  1093. /*
  1094.  *    **************************************************
  1095.  *    *                                                *
  1096.  *    *             Display Help Screen 3              *
  1097.  *    *                                                *
  1098.  *    **************************************************
  1099.  */
  1100.  
  1101. static void HelpScreen3(void)
  1102.  
  1103. {
  1104.  
  1105.    Heading1();
  1106.  
  1107.    WriteAt( 3,  1, "This program emulates a Hewlett-Packard calculator w"
  1108.                    "ith four register stack");
  1109.    WriteAt( 4,  1, "and ten memory registers.  The stack consists of the"
  1110.                    " X, Y, Z & T registers.");
  1111.    WriteAt( 5,  1, "The memory registers are 0-9.");
  1112.  
  1113.    WriteAt( 7,  1, "The X register is 'where the action is'.  When you e"
  1114.                    "nter a number it is entered");
  1115.    WriteAt( 8,  1, "into the X register.  If X already contains a number"
  1116.                    ", that number is 'pushed'");
  1117.    WriteAt( 9,  1, "up to Y, Y is pushed to Z, Z to T, and the contents "
  1118.                    "of T is lost.  The 'Enter'");
  1119.    WriteAt(10,  1, "key pushes the stack and duplicates X into Y. A numb"
  1120.                    "er entered into X after");
  1121.    WriteAt(11,  1, "Enter or ClearX DOES NOT push the stack. When you us"
  1122.                    "e a function that acts on");
  1123.    WriteAt(12,  1, "two numbers (like + or -) it always acts on X & Y (e"
  1124.                    "xcept for Store, Recall &");
  1125.    WriteAt(13,  1, "eXchange which act on X and a memory register).  The"
  1126.                    " result is put in X, and");
  1127.    WriteAt(14,  1, "the stack is 'Dropped'.  That is, Z copies to Y and "
  1128.                    "T duplicates into Z.");
  1129.  
  1130.    WriteAt(16,  1, "Numbers are displayed in 'Floating Decimal' or 'Scie"
  1131.                    "ntific Notation' format.");
  1132.    WriteAt(17,  1, "Floating Decimal looks like this:    1.2     123.45 "
  1133.                    "    -12300000000  0.000002");
  1134.    WriteAt(18,  1, "Scientific Notation looks like this: 1.2 e0  1.2345 "
  1135.                    "e2  -1.23 e10     2.0 e-6");
  1136.    WriteAt(19,  1, "Very long numbers take longer to compute, of course."
  1137.                    " You can abort a long");
  1138.    WriteAt(20,  1, "calculation by pressing the Escape key.");
  1139.  
  1140.    WriteAt(22,  1, "If a number is too large or small for the screen, Sc"
  1141.                    "ientific Notation is used.");
  1142.    WriteAt(23,  1, "All results are truncated except for Y^X which is ro"
  1143.                    "unded: 5 up 4 down.");
  1144.  
  1145. }
  1146.  
  1147.  
  1148.  
  1149.  
  1150. /*
  1151.  *    **************************************************
  1152.  *    *                                                *
  1153.  *    *              Display Work Screen               *
  1154.  *    *                                                *
  1155.  *    **************************************************
  1156.  */
  1157.  
  1158. extern void WorkScreen(void)
  1159.  
  1160. {
  1161.  
  1162.    int r, s;
  1163.  
  1164.    Heading1();
  1165.    Heading2();
  1166.  
  1167.    WriteAt(3, 1, "============================="
  1168.                  "  R E G I S T E R S  "
  1169.                  "=============================");
  1170.    for (r = 0; r <= 9; r++) {
  1171.       CurPos(4 + r, 1);
  1172.       WChar(r + '0');
  1173.       WChar(':');
  1174.       WriteReg(r, r);
  1175.    }
  1176.  
  1177.    WriteAt(14, 1, "================================="
  1178.                   "  S T A C K  "
  1179.                   "=================================");
  1180.    for (s = 3; s >= 0; s--) {
  1181.       CurPos(XSIGNROW - s, 1);
  1182.       WChar(stackname[s]);
  1183.       WChar(':');
  1184.       WriteStack(s, s);
  1185.    }
  1186.  
  1187. }
  1188.