home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / menu / cmenu / shortlib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-01  |  6.6 KB  |  216 lines

  1. #include "menudrv.h"
  2. #include "menudrv.def"
  3. #include <alloc.h>
  4. #include <dos.h>
  5. #include <mem.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <conio.h>
  10.  
  11. /* Important! Use a memory model which employs far data pointers so that
  12.    these routines can access video memory directly; suggest: compact model;
  13.    otherwise, the FP_SET and FP_OFF functions will not work!! */
  14. /*=========================================================================*/
  15. /*  short.lib -- library of get functions for use by Turbo C menu driver;  */
  16. /*  includes the following screen functions:                               */
  17. /*                                                                         */
  18. /*    binit;  <allocate buffers>                                           */
  19. /*    savescreen(b);  <save current video display to buffer b (0..4)>      */
  20. /*    restorescreen(b);  <restore video display from buffer b>             */
  21. /*    bclear(b); <clear buffer b using current bfore, bback color codes>   */
  22. /*    bwrite(b,x,y,str); <insert string <str> into buffer b at (x,y)>      */
  23. /*                                                                         */
  24. /*=========================================================================*/
  25.  
  26.  
  27. void binit(void)  /* initialize video buffers */
  28. {
  29.    int i;
  30.    union REGS regs;
  31.  
  32.    for ( i = 0; i <= 4; ++i ) {
  33.       sbuff[i] = calloc(1,sizeof(*sbuff[i]));
  34.    }
  35.    bfore = WHITE;
  36.    bback = BLACK;
  37.    /*determine whether display is monochrome or color*/
  38.    regs.x.ax = 0;
  39.    int86(17,®s,®s);  /*equipment list call*/
  40.    if ( (regs.h.al & 48) == (48) ) {
  41.       monochrome = TRUE;
  42.    }
  43.    else {
  44.       monochrome = FALSE;
  45.    }
  46.    initialized = TRUE;
  47. }
  48.  
  49. /*====================================================*/
  50.  
  51. void savescreen(int i)
  52. {
  53.    unsigned char b;
  54.  
  55.    if ( ! initialized ) {
  56.       cprintf("%s%s%s\n", "** savescreen routine called without buffer ",
  57.        "initialization **",
  58.        "\x07\x07");
  59.       return;
  60.    }
  61.  
  62.    b = peek(0,1125);
  63.    outportb(984,(b & 240) | 1);  /*blank screen*/
  64.    if ( monochrome ) {
  65.       movedata(0xb000,0,FP_SEG(sbuff[i]),FP_OFF(sbuff[i]),4000);
  66.    }
  67.    else {
  68.       movedata(0xb800,0,FP_SEG(sbuff[i]),FP_OFF(sbuff[i]),4000);
  69.    }
  70.    outportb(984,b);
  71. }
  72.  
  73. /*====================================================*/
  74.  
  75. void restorescreen(int i)
  76. {
  77.    unsigned char b;
  78.  
  79.    if ( ! initialized ) {
  80.       cprintf("%s%s%s\n",
  81.       "** restorescreen routine called without buffer ",
  82.       "initialization **", "\x07\x07");
  83.       return;
  84.    }
  85.    b = peek(0,1125); /*DOS video mode byte reference*/
  86.    outportb(984,(b & 240) | 1);  /*blank screen*/
  87.    if ( monochrome ) {
  88.       movedata(FP_SEG(sbuff[i]),FP_OFF(sbuff[i]),0xb000,0,4000);
  89.    }
  90.    else {
  91.       movedata(FP_SEG(sbuff[i]),FP_OFF(sbuff[i]),0xb800,0,4000);
  92.    }
  93.    poke(0,1125,b & 223);
  94.    outportb(984,b & 223);
  95. }
  96.  
  97. /*====================================================*/
  98.  
  99. void copyscreen(int i,int j)
  100. {
  101.  
  102.    if ( ! initialized ) {
  103.       cprintf("%s%s%s\n",
  104.       "** copyscreen routine called without buffer ",
  105.       "initialization **", "\x07\x07");
  106.       return;
  107.    }
  108.    if ((i<0) || (i>4)) {
  109.       return;
  110.    }
  111.    movedata(FP_SEG(sbuff[i]),FP_OFF(sbuff[i]),
  112.      FP_SEG(sbuff[j]),FP_OFF(sbuff[j]),4000);
  113. }
  114. /*====================================================*/
  115.  
  116. void bclear(int b)
  117. {
  118.    int i;
  119.  
  120.    if ( ! initialized ) {
  121.       cprintf("%s%s%s\n", "** bclear routine called without buffer ",
  122.       "initialization **", "\x07\x07");
  123.       return;
  124.    }
  125.    i = 0;
  126.    while ( i < 4000 ) {
  127.       (*sbuff[b])[i] = 32;  /*ASCII blank*/
  128.       (*sbuff[b])[i + 1] = (bback) * 16 + bfore;
  129.       i += 2;
  130.    }
  131. }  /*bclear*/
  132.  
  133. /*====================================================*/
  134.  
  135. void bwrite(int b,int x,int y,char st[])
  136. {
  137.    int i;
  138.    int p;
  139.  
  140.    if ( ! initialized ) {
  141.       cprintf("%s%s%s\n", "** bwrite routine called without buffer ",
  142.       "initialization **", "\x07\x07");
  143.       return;
  144.    }
  145.    p = ((y - 1) * 160) + ((x - 1) * 2) ;  /*starting position in buffer*/
  146.    for ( i = 0; i < strlen(st); i++) {
  147.       (*sbuff[b])[p] = st[i];
  148.       (*sbuff[b])[p + 1] = (bback) * 16 + bfore;
  149.       p += 2;
  150.    } /*for i*/
  151. }  /*bwrite*/
  152.  
  153. /*=========================================================================*/
  154.  
  155. void border(color)
  156. int color;
  157. {
  158.    union REGS regs;
  159.  
  160.    regs.h.ah = 11; /*set color palette*/
  161.    regs.h.bh = 0;
  162.    regs.h.bl = color;
  163.    int86(16,®s,®s); /*video services*/
  164.  
  165. } /*border*/
  166.  
  167. /*=========================================================================*/
  168.  
  169. int color(char st[])
  170. {
  171.    int _fret;
  172.  
  173.    if ( (strcmp(st,"black") == 0) ) _fret = BLACK;
  174.    else if ( (strcmp(st, "white") == 0) ) _fret = WHITE;
  175.    else if ( (strcmp(st, "blue") == 0) ) _fret = BLUE;
  176.    else if ( (strcmp(st, "cyan") == 0) ) _fret = CYAN;
  177.    else if ( (strcmp(st, "green") == 0) ) _fret = GREEN;
  178.    else if ( (strcmp(st, "red") == 0) ) _fret = RED;
  179.    else if ( (strcmp(st, "magenta") == 0) ) _fret = MAGENTA;
  180.    else if ( (strcmp(st, "brown") == 0) ) _fret = BROWN;
  181.    else if ( (strcmp(st, "yellow") == 0) ) _fret = YELLOW;
  182.    else if ( (strcmp(st, "lightgray") == 0) ) _fret = LIGHTGRAY;
  183.    else if ( (strcmp(st, "darkgray") == 0) ) _fret = DARKGRAY;
  184.    else if ( (strcmp(st, "lightblue") == 0) ) _fret = LIGHTBLUE;
  185.    else if ( (strcmp(st, "lightgreen") == 0) ) _fret = LIGHTGREEN;
  186.    else if ( (strcmp(st, "lightcyan") == 0) ) _fret = LIGHTCYAN;
  187.    else if ( (strcmp(st, "lightred") == 0) ) _fret = LIGHTRED;
  188.    else if ( (strcmp(st, "lightmagenta") == 0) ) _fret = LIGHTMAGENTA;
  189.    else _fret = WHITE;
  190.    return(_fret);
  191. }
  192.  
  193. /*=========================================================================*/
  194.  
  195. void colorval(int color,char st[])
  196. {
  197.  
  198.    if ( color == BLACK ) strcpy(st,"black");
  199.    else if ( color == WHITE ) strcpy(st,"white");
  200.    else if ( color == BLUE ) strcpy(st,"blue");
  201.    else if ( color == CYAN ) strcpy(st,"cyan");
  202.    else if ( color == GREEN ) strcpy(st,"green");
  203.    else if ( color == RED ) strcpy(st,"red");
  204.    else if ( color == MAGENTA ) strcpy(st,"magenta");
  205.    else if ( color == BROWN ) strcpy(st,"brown");
  206.    else if ( color == YELLOW ) strcpy(st,"yellow");
  207.    else if ( color == LIGHTGRAY ) strcpy(st,"lightgray");
  208.    else if ( color == DARKGRAY ) strcpy(st,"darkgray");
  209.    else if ( color == LIGHTBLUE ) strcpy(st,"lightblue");
  210.    else if ( color == LIGHTGREEN ) strcpy(st,"lightgreen");
  211.    else if ( color == LIGHTCYAN ) strcpy(st,"lightcyan");
  212.    else if ( color == LIGHTRED ) strcpy(st,"lightred");
  213.    else if ( color == LIGHTMAGENTA ) strcpy(st,"lightmagenta");
  214.    else strcpy(st,"WHITE");
  215. }
  216.