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

  1. /*
  2.  *    **************************************************
  3.  *    *                                                *
  4.  *    *                    BIGIO.C                     *
  5.  *    *                                                *
  6.  *    *          Extended Precision Calculator         *
  7.  *    *                                                *
  8.  *    *             Low Level I/O 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 <conio.h>
  32. #include <ctype.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include "bigcalc.h"
  37. #include "biggvar.h"
  38.  
  39. #ifdef REALMODE
  40. #include <dos.h>
  41. #else
  42. #define INCL_BASE
  43. #include <os2.h>
  44. #endif
  45.  
  46.  
  47. /*
  48.  *    **************************************************
  49.  *    *                                                *
  50.  *    *                   Constants                    *
  51.  *    *                                                *
  52.  *    **************************************************
  53.  */
  54.  
  55. #define CLOCKFREQ       1193180L    /* Timer frequency        */
  56. #define SPEAKERMODE     0xB6        /* Set timer for speaker  */
  57. #define TIMERMODEPORT   0x43        /* Timer mode port        */
  58. #define FREQPORT        0x42        /* Frequency-control port */
  59. #define SPEAKERPORT     0x61        /* Speaker port           */
  60. #define SPEAKERON       0x03        /* Speaker-on bits        */
  61. #define FREQ            400         /* A frequency            */
  62. #define CFREQ  CLOCKFREQ / FREQ     /* Division frequency     */
  63.  
  64. #define SCRCOLOR        0x07        /* Grey on black          */
  65. #define MONOSCREEN      0xB0000000L /* Mono buffer address    */
  66. #define COLORSCREEN     0xB8000000L /* Color buffer address   */
  67.  
  68.  
  69.  
  70.  
  71.  
  72. /*
  73.  *    **************************************************
  74.  *    *                                                *
  75.  *    *            Source Local Variables              *
  76.  *    *                                                *
  77.  *    **************************************************
  78.  */
  79.  
  80. typedef struct {                 /* Screen char struct */
  81.    char
  82.       data,
  83.       attr;
  84.    } CHTYPE;
  85.  
  86. typedef struct {                 /* Screen memory structure */
  87.    CHTYPE ch[25][80];
  88.    } far *SCREENTYPE;
  89.  
  90. static SCREENTYPE                /* Screen pointer  */
  91.    scr;
  92.  
  93. static int
  94.    arow = 0,                     /* Absolute row    */
  95.    acol = 0;                     /* Absolute column */
  96.  
  97. #ifdef REALMODE
  98. static union REGS
  99.    cpu;                          /* CPU registers for int86() */
  100. static struct SREGS
  101.    segs;
  102. #endif
  103.  
  104. static unsigned short cbLVB;     /* length of LVB */
  105.  
  106.  
  107.  
  108.  
  109. /*
  110.  *    **************************************************
  111.  *    *                                                *
  112.  *    *              Keyboard Routines                 *
  113.  *    *                                                *
  114.  *    **************************************************
  115.  */
  116.  
  117.  
  118. /*
  119.  *    **************************************************
  120.  *    *                                                *
  121.  *    *         Get decoded character from kbd         *
  122.  *    *                                                *
  123.  *    **************************************************
  124.  */
  125.  
  126. extern int GetChar(void)
  127.  
  128. {
  129.    int chr;
  130.  
  131.    CurPos(arow + 1, acol + 1);
  132.  
  133. #ifdef REALMODE                  /* Show logical video buffer */
  134.    cpu.x.cx = cbLVB;
  135.    segs.es = FP_SEG(scr);
  136.    cpu.x.di = FP_OFF(scr);
  137.    cpu.h.ah = 255;
  138.    int86x(16, &cpu, &cpu, &segs);
  139. #else
  140.    VioShowBuf(0, cbLVB, 0);
  141. #endif
  142.  
  143.    chr = getch();
  144.    if (chr == 0)
  145.       chr = 1000 + getch();      /* Non ASCII character */
  146.    else
  147.       if (isascii(chr) )
  148.          chr = toupper(chr);
  149.  
  150.    return(chr);
  151. }
  152.  
  153.  
  154.  
  155.  
  156. /*
  157.  *    **************************************************
  158.  *    *                                                *
  159.  *    *         Return character if key pressed        *
  160.  *    *                                                *
  161.  *    **************************************************
  162.  */
  163.  
  164. extern int KeyPressed(void)
  165.  
  166. {
  167.    if (kbhit())
  168.       return(GetChar());
  169.    else
  170.       return(0);
  171. }
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. /*
  179.  *    **************************************************
  180.  *    *                                                *
  181.  *    *                Screen Routines                 *
  182.  *    *                                                *
  183.  *    **************************************************
  184.  */
  185.  
  186.  
  187. /*
  188.  *    **************************************************
  189.  *    *                                                *
  190.  *    *            Initialize Screen Drivers           *
  191.  *    *                                                *
  192.  *    **************************************************
  193.  */
  194.  
  195. extern void ScrInit(void)
  196.  
  197. {
  198.             /* Get far pointer to screen buffer */
  199.  
  200. #ifdef REALMODE
  201.  
  202.    cpu.h.ah = 15;                /* Get video mode */
  203.    int86(16, &cpu, &cpu);
  204.  
  205.    if ( (cpu.h.al != 2)          /* 80x25 b/w   */
  206.          &&
  207.         (cpu.h.al != 3)          /* 80x25 color */
  208.          &&
  209.         (cpu.h.al != 7) ) {      /* 80x25 mono  */
  210.       puts("Display must be in 80x25 text mode");
  211.       exit(1);
  212.       }
  213.  
  214.    if (cpu.h.al == 7)
  215.       scr = (SCREENTYPE)((void far *)MONOSCREEN);
  216.    else
  217.       scr = (SCREENTYPE)((void far *)COLORSCREEN);
  218.  
  219.   segs.es = FP_SEG(scr);
  220.   cpu.x.di = FP_OFF(scr);
  221.  
  222.   cpu.h.ah = 254;
  223.   int86x(16, &cpu, &cpu, &segs);
  224.  
  225.   FP_SEG(scr) = segs.es;
  226.   FP_OFF(scr) = cpu.x.di;
  227.   cbLVB = 25*80;
  228.  
  229. #else
  230.  
  231.    VIOMODEINFO viomiMode;
  232.    viomiMode.cb = sizeof(viomiMode);
  233.    VioGetMode(&viomiMode, 0);
  234.    if ( (viomiMode.row != 25)
  235.          ||
  236.         (viomiMode.col != 80) ) {
  237.       puts("Display must be in 80x25 text mode");
  238.       exit(1);
  239.       }
  240.  
  241.    VioGetBuf((PULONG) &scr, (PUSHORT) &cbLVB, 0);
  242.  
  243. #endif
  244.  
  245. }
  246.  
  247.  
  248.  
  249.  
  250. /*
  251.  *    **************************************************
  252.  *    *                                                *
  253.  *    *            End of Job Screen Cleanup           *
  254.  *    *                                                *
  255.  *    **************************************************
  256.  */
  257.  
  258. extern void ScrTerm(void)
  259.  
  260. {
  261.  
  262.    if (printid[0] == 'B')        /* Close BIGCALC.PRN if open */
  263.       fclose(printfile);
  264.  
  265.    CurPos(XSIGNROW + 1, 1);
  266.    EraEop();
  267.  
  268. #ifdef REALMODE                  /* Show logical video buffer */
  269.    cpu.x.cx = cbLVB;
  270.    segs.es = FP_SEG(scr);
  271.    cpu.x.di = FP_OFF(scr);
  272.    cpu.h.ah = 255;
  273.    int86x(16, &cpu, &cpu, &segs);
  274. #else
  275.    VioShowBuf(0, cbLVB, 0);
  276. #endif
  277.  
  278. }
  279.  
  280.  
  281.  
  282.  
  283. /*
  284.  *    **************************************************
  285.  *    *                                                *
  286.  *    *                Clear the Screen                *
  287.  *    *                                                *
  288.  *    **************************************************
  289.  */
  290.  
  291. extern void ScrClr(void)
  292.  
  293. {
  294.  
  295.    CurPos(1, 1);
  296.    EraEop();
  297.  
  298. }
  299.  
  300.  
  301.  
  302.  
  303. /*
  304.  *    **************************************************
  305.  *    *                                                *
  306.  *    *              Erase to End of Line              *
  307.  *    *                                                *
  308.  *    **************************************************
  309.  */
  310.  
  311. extern void EraEol(void)
  312.  
  313. {
  314.  
  315.    WNChar(' ', (80 - acol));
  316.  
  317. }
  318.  
  319.  
  320.  
  321.  
  322. /*
  323.  *    **************************************************
  324.  *    *                                                *
  325.  *    *              Erase to End of Page              *
  326.  *    *                                                *
  327.  *    **************************************************
  328.  */
  329.  
  330. extern void EraEop(void)
  331.  
  332. {
  333.  
  334.    WNChar(' ', (80 * (24 - arow) + 80 - acol));
  335.  
  336. }
  337.  
  338.  
  339.  
  340.  
  341. /*
  342.  *    **************************************************
  343.  *    *                                                *
  344.  *    *         Position Cursor at row, column         *
  345.  *    *                                                *
  346.  *    **************************************************
  347.  */
  348.  
  349. extern void CurPos(int row, int col)
  350.  
  351. {
  352.  
  353.    arow = row - 1;
  354.    acol = col - 1;
  355.  
  356. #ifdef REALMODE
  357.    cpu.h.ah = 2;                 /* Set cursor position */
  358.    cpu.h.dh = (char) arow;
  359.    cpu.h.dl = (char) acol;
  360.    cpu.h.bh = 0;
  361.    int86(16, &cpu, &cpu);
  362. #else
  363.    VioSetCurPos(arow, acol, 0);
  364. #endif
  365.  
  366. }
  367.  
  368.  
  369.  
  370.  
  371. /*
  372.  *    **************************************************
  373.  *    *                                                *
  374.  *    *            Get Cursor row, column              *
  375.  *    *                                                *
  376.  *    **************************************************
  377.  */
  378.  
  379. extern void CurGet(int *row, int *col)
  380.  
  381. {
  382.  
  383.    *row = arow + 1;
  384.    *col = acol + 1;
  385.  
  386. }
  387.  
  388.  
  389.  
  390.  
  391. /*
  392.  *    **************************************************
  393.  *    *                                                *
  394.  *    *     Write Character count times to Screen      *
  395.  *    *                                                *
  396.  *    **************************************************
  397.  */
  398.  
  399. static void WNChar(int chr, int count)
  400.  
  401. {
  402.  
  403.    CHTYPE byte, far *pos, far *pend;
  404.  
  405.    pos = &scr->ch[arow][acol];
  406.    pend = pos + count;
  407.    byte.data = (char)chr;
  408.    byte.attr = SCRCOLOR;
  409.  
  410.    while (pos < pend)
  411.       *pos++ = byte;
  412.  
  413. }
  414.  
  415.  
  416.  
  417.  
  418. /*
  419.  *    **************************************************
  420.  *    *                                                *
  421.  *    *            Write Character to Screen           *
  422.  *    *                                                *
  423.  *    **************************************************
  424.  */
  425.  
  426. extern void WChar(int chr)
  427.  
  428. {
  429.  
  430.    scr->ch[arow][acol].data = (char)chr;
  431.    if (++acol > 79) {
  432.       arow++;
  433.       acol = 0;
  434.       }
  435.  
  436. }
  437.  
  438.  
  439.  
  440.  
  441. /*
  442.  *    **************************************************
  443.  *    *                                                *
  444.  *    *             Write String to Screen             *
  445.  *    *                                                *
  446.  *    **************************************************
  447.  */
  448.  
  449. extern void WString(char *str)
  450.  
  451. {
  452.  
  453.    while (*str) {
  454.       scr->ch[arow][acol].data = *(str++);
  455.       if (++acol > 79) {
  456.          arow++;
  457.          acol = 0;
  458.          }
  459.       }
  460.  
  461. }
  462.  
  463.  
  464.  
  465.  
  466. /*
  467.  *    **************************************************
  468.  *    *                                                *
  469.  *    *             Write Integer to Screen            *
  470.  *    *                                                *
  471.  *    **************************************************
  472.  */
  473.  
  474. extern void WInteger(long integer)
  475.  
  476. {
  477.  
  478.    long order;
  479.  
  480.    if (integer) {
  481.       if (integer < 0L) {
  482.          WChar('-');
  483.          integer = - integer;
  484.          }
  485.       order = 1000000000L;
  486.       while (order > integer) {
  487.          order /= 10L;
  488.          }
  489.       while (order) {
  490.          WChar((int)((integer / order) + (long)'0'));
  491.          integer %= order;
  492.          order /= 10L;
  493.          }
  494.       }
  495.    else
  496.       WChar('0');
  497.  
  498. }
  499.  
  500.  
  501.  
  502.  
  503. /*
  504.  *    **************************************************
  505.  *    *                                                *
  506.  *    *       Write String at row, col to Screen       *
  507.  *    *                                                *
  508.  *    **************************************************
  509.  */
  510.  
  511. extern void WriteAt(int row, int col, char *str)
  512.  
  513. {
  514.  
  515.    CurPos(row, col);
  516.    WString(str);
  517.  
  518. }
  519.  
  520.  
  521.  
  522.  
  523. /*
  524.  *    **************************************************
  525.  *    *                                                *
  526.  *    *     Display Message centered on row line       *
  527.  *    *                                                *
  528.  *    **************************************************
  529.  */
  530.  
  531. extern void WriteCenter(int row, char *msg)
  532.  
  533. {
  534.  
  535.    CurPos(row, 1);
  536.    EraEol();
  537.  
  538.    CurPos(row, ((80 - strlen(msg)) / 2));
  539.    WString(msg);
  540.  
  541. }
  542.  
  543.  
  544.  
  545.  
  546. /*
  547.  *    **************************************************
  548.  *    *                                                *
  549.  *    *      Display Message centered on 25th line     *
  550.  *    *                                                *
  551.  *    **************************************************
  552.  */
  553.  
  554. extern void Message(char *msg)
  555.  
  556. {
  557.  
  558.    WriteCenter(25, msg);
  559.  
  560. #ifdef REALMODE                  /* Show logical video buffer */
  561.    cpu.x.cx = cbLVB;
  562.    segs.es = FP_SEG(scr);
  563.    cpu.x.di = FP_OFF(scr);
  564.    cpu.h.ah = 255;
  565.    int86x(16, &cpu, &cpu, &segs);
  566. #else
  567.    VioShowBuf(0, cbLVB, 0);
  568. #endif
  569.  
  570. }
  571.  
  572.  
  573.  
  574.  
  575. /*
  576.  *    **************************************************
  577.  *    *                                                *
  578.  *    *      Write Message and Wait for keystroke      *
  579.  *    *                                                *
  580.  *    **************************************************
  581.  */
  582.  
  583. extern void MessageWait(char *msg)
  584.  
  585. {
  586.  
  587.    char tmsg[81];
  588.  
  589.    strcpy(tmsg, msg);
  590.    if (*tmsg)
  591.       strcat(tmsg, "  ");
  592.    strcat(tmsg, "(Press a key to continue)");
  593.  
  594.    Message(tmsg);
  595.    GetChar();
  596.  
  597. }
  598.  
  599.  
  600.  
  601.  
  602. /*
  603.  *    **************************************************
  604.  *    *                                                *
  605.  *    *      Write Message and Prompt for Escape       *
  606.  *    *                                                *
  607.  *    **************************************************
  608.  */
  609.  
  610. extern void MessageEsc(char *msg)
  611.  
  612. {
  613.  
  614.    char tmsg[81];
  615.  
  616.    strcpy(tmsg, msg);
  617.    if (*tmsg)
  618.       strcat(tmsg, "... ");
  619.    strcat(tmsg, "(Press Esc to abort)");
  620.  
  621.    Message(tmsg);
  622.  
  623. }
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630. /*
  631.  *    **************************************************
  632.  *    *                                                *
  633.  *    *         Number Entry Support Routines          *
  634.  *    *                                                *
  635.  *    **************************************************
  636.  */
  637.  
  638.  
  639. /*
  640.  *    **************************************************
  641.  *    *                                                *
  642.  *    *         Display Character at row, col          *
  643.  *    *                                                *
  644.  *    **************************************************
  645.  */
  646.  
  647. extern void DisplayChar(int *row, int *col, int chr)
  648.  
  649. {
  650.  
  651.    CurPos(*row, *col);
  652.    WChar(chr);
  653.  
  654.    if (*col < MAXDISPCOL)     /* Find position for next character */
  655.       (*col)++;
  656.    else {
  657.       *col = MINDISPCOL;
  658.       (*row)++;
  659.       }
  660.    CurPos(*row, *col);
  661.  
  662. }
  663.  
  664.  
  665.  
  666.  
  667. /*
  668.  *    **************************************************
  669.  *    *                                                *
  670.  *    *               Backspace Character              *
  671.  *    *                                                *
  672.  *    **************************************************
  673.  */
  674.  
  675. extern void BackSpace(int *row, int *col)
  676.  
  677. {
  678.  
  679.    if (*col > MINDISPCOL)     /* find previous character position */
  680.       (*col)--;
  681.    else {
  682.       *col = MAXDISPCOL;
  683.       (*row)--;
  684.       }
  685.  
  686.    CurPos(*row, *col);
  687.    WChar(' ');
  688.    CurPos(*row, *col);
  689.  
  690. }
  691.  
  692.  
  693.  
  694.  
  695. /*
  696.  *    **************************************************
  697.  *    *                                                *
  698.  *    *     Display Exponent Character at row, col     *
  699.  *    *                                                *
  700.  *    **************************************************
  701.  */
  702.  
  703. extern void DisplayExpChar(int *row, int *col, int chr)
  704.  
  705. {
  706.  
  707.    CurPos(*row, *col);
  708.    WChar(chr);
  709.  
  710.    if (*col < 80)             /* Find position for next character */
  711.       (*col)++;
  712.    else {
  713.       *col = MINDISPCOL;
  714.       (*row)++;
  715.       }
  716.    CurPos(*row, *col);
  717.  
  718. }
  719.  
  720.  
  721.  
  722.  
  723. /*
  724.  *    **************************************************
  725.  *    *                                                *
  726.  *    *          Backspace Exponent Character          *
  727.  *    *                                                *
  728.  *    **************************************************
  729.  */
  730.  
  731. extern void BackSpaceExp(int *row, int *col)
  732.  
  733. {
  734.  
  735.    if (*col > MINDISPCOL)     /* find previous character position */
  736.       (*col)--;
  737.    else {
  738.       *col = 80;
  739.       (*row)--;
  740.       }
  741.  
  742.    CurPos(*row, *col);
  743.    WChar(' ');
  744.    CurPos(*row, *col);
  745.  
  746. }
  747.  
  748.  
  749.  
  750.  
  751. /*
  752.  *    **************************************************
  753.  *    *                                                *
  754.  *    *          Display Exponent at row, col          *
  755.  *    *                                                *
  756.  *    **************************************************
  757.  */
  758.  
  759. extern void DisplayExp(int *row, int *col, int exprow, int expcol, int expsign, long exponent)
  760.  
  761. {
  762.  
  763.    long order;
  764.  
  765.  
  766.    *row = exprow;
  767.    *col = expcol;
  768.    CurPos(exprow, expcol);          /* Locate to beginning of exponent */
  769.    EraEol();
  770.  
  771.    if (expsign == '-')
  772.       DisplayExpChar(row, col, '-');
  773.  
  774.    if (exponent) {                  /* Write exponent value */
  775.       if (exponent < 0L) {
  776.          DisplayExpChar(row, col, '-');
  777.          exponent = - exponent;
  778.          }
  779.       order = 1000000000L;
  780.       while (order > exponent)
  781.          order /= 10L;
  782.       while (order) {
  783.          DisplayExpChar(row, col, (int)((exponent / order) + (long) '0'));
  784.          exponent %= order;
  785.          order /= 10L;
  786.          }
  787.       }
  788.  
  789. }
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. /*
  797.  *    **************************************************
  798.  *    *                                                *
  799.  *    *               Printer Routines                 *
  800.  *    *                                                *
  801.  *    **************************************************
  802.  */
  803.  
  804.  
  805. /*
  806.  *    **************************************************
  807.  *    *                                                *
  808.  *    *           Print Character on Printer           *
  809.  *    *                                                *
  810.  *    **************************************************
  811.  */
  812.  
  813. extern void PChar(int chr)
  814.  
  815. {
  816.  
  817.    if (!printtoscreen) {         /* If using printer or disk ... */
  818.       fputc(chr, printfile);
  819.       return;
  820.       }
  821.  
  822.             /* Direct screen output */
  823.  
  824.    if (chr == CR) {              /* Carriage Return */
  825.       acol = 0;
  826.       }
  827.    else if (chr == LF) {         /* Line Feed */
  828.       arow++;
  829.       acol = 0;
  830.       }
  831.    else if (chr == FF) {         /* Form Feed */
  832.       }
  833.    else {
  834.       scr->ch[arow][acol].data = (char)chr;
  835.       if (++acol > 79) {
  836.          arow++;
  837.          acol = 0;
  838.          }
  839.       }
  840.  
  841. }
  842.  
  843.  
  844.  
  845.  
  846. /*
  847.  *    **************************************************
  848.  *    *                                                *
  849.  *    *            Print String on Printer             *
  850.  *    *                                                *
  851.  *    **************************************************
  852.  */
  853.  
  854. extern void PString(char *str)
  855.  
  856. {
  857.  
  858.    if (!printtoscreen) {            /* If using printer or disk ... */
  859.       fputs(str, printfile);
  860.       return;
  861.       }
  862.  
  863.             /* Direct screen output */
  864.  
  865.    while (*str) {
  866.       if (*str == CR) {             /* Carriage Return */
  867.          acol = 0;
  868.          }
  869.       else if (*str == LF) {        /* Line Feed */
  870.          arow++;
  871.          acol = 0;
  872.          }
  873.       else if (*str == FF) {        /* Form Feed */
  874.          }
  875.       else {
  876.          scr->ch[arow][acol].data = *(str);
  877.          if (++acol > 79) {
  878.             arow++;
  879.             acol = 0;
  880.             }
  881.          }
  882.       str++;
  883.       }
  884.  
  885. }
  886.  
  887.  
  888.  
  889.  
  890. /*
  891.  *    **************************************************
  892.  *    *                                                *
  893.  *    *            Print Integer on Printer            *
  894.  *    *                                                *
  895.  *    **************************************************
  896.  */
  897.  
  898. extern void PInteger(long integer)
  899.  
  900. {
  901.  
  902.    long order;
  903.  
  904.    if (integer) {
  905.       if (integer < 0L) {
  906.          PChar('-');
  907.          integer = - integer;
  908.          }
  909.       order = 1000000000L;
  910.       while (order > integer) {
  911.          order /= 10L;
  912.          }
  913.       while (order) {
  914.          PChar((int)((integer / order) + (long)'0'));
  915.          integer %= order;
  916.          order /= 10L;
  917.          }
  918.       }
  919.    else
  920.       PChar('0');
  921.  
  922. }
  923.  
  924.  
  925.  
  926.  
  927. /*
  928.  *    **************************************************
  929.  *    *                                                *
  930.  *    *              New Line on Printer               *
  931.  *    *                                                *
  932.  *    **************************************************
  933.  */
  934.  
  935. extern void NewLine(void)
  936.  
  937. {
  938.  
  939.    PString("\r\n");
  940.  
  941. }
  942.  
  943.  
  944.  
  945.  
  946. /*
  947.  *    **************************************************
  948.  *    *                                                *
  949.  *    *              New Page on Printer               *
  950.  *    *                                                *
  951.  *    **************************************************
  952.  */
  953.  
  954. extern void NewPage(void)
  955.  
  956. {
  957.  
  958.    PString("\r\f");
  959.  
  960. }
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967. /*
  968.  *    **************************************************
  969.  *    *                                                *
  970.  *    *          Miscellaneous I/O Routines            *
  971.  *    *                                                *
  972.  *    **************************************************
  973.  */
  974.  
  975.  
  976. /*
  977.  *    **************************************************
  978.  *    *                                                *
  979.  *    *                 Beep speaker                   *
  980.  *    *                                                *
  981.  *    **************************************************
  982.  */
  983.  
  984. extern void Beep(void)
  985.  
  986. {
  987.  
  988. #ifdef REALMODE
  989.    static long endtime;
  990.    static unsigned char saveport;
  991.  
  992.    outp(TIMERMODEPORT, SPEAKERMODE);
  993.    saveport = (unsigned char) inp(SPEAKERPORT);
  994.  
  995.    outp(FREQPORT, CFREQ & 0xFF);          /* Start tone */
  996.    outp(FREQPORT, CFREQ >> 8);
  997.    outp(SPEAKERPORT, saveport | SPEAKERON);
  998.  
  999.    endtime = TimerTicks() + 2L;           /* Pause 2 clock ticks */
  1000.    while (TimerTicks() < endtime)
  1001.       ;
  1002.  
  1003.    outp(SPEAKERPORT, saveport);           /* Stop tone */
  1004. #else
  1005.    DosBeep(1000, 125);                    /* 1/8 second beep */
  1006. #endif
  1007.  
  1008. }
  1009.  
  1010.  
  1011.  
  1012.  
  1013. /*
  1014.  *    **************************************************
  1015.  *    *                                                *
  1016.  *    *         Fetch Timer Ticks since Midnight       *
  1017.  *    *                                                *
  1018.  *    **************************************************
  1019.  */
  1020. #ifdef REALMODE
  1021. extern long TimerTicks(void)
  1022. {
  1023.  
  1024.    static long ticks;
  1025.  
  1026.    cpu.h.ah = 0;
  1027.    int86(0x1A, &cpu, &cpu);
  1028.  
  1029.    ticks = (((long) cpu.x.cx) << 16) + ((long) cpu.x.dx);
  1030.    return(ticks);
  1031.  
  1032. }
  1033. #endif
  1034.