home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / PCBIOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  9.4 KB  |  402 lines

  1. /*
  2.     pcbios.c
  3.  
  4.     % pc BIOS device interface
  5.  
  6.     5/16/88  by Ted.
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      8/31/88 Ted    Added actual BIOS code.
  15.     01/10/89 ted    Removed redundant disp clip.
  16.      1/18/89 Ted    changed call to PlotText for simplified interface.
  17.      2/04/89 Ted    removed Read and Draw Pixmap functions.
  18.      7/12/89 ted    Added OSTATIC's and '_func' macros.
  19. */
  20.  
  21. #include "pcpriv.h"
  22.  
  23. OSTATIC boolean    DIGPRIV pc_OpenBIOS(_arg2(dig_struct *, int));
  24. OSTATIC dig_dControl_func        (text_bControl);
  25. OSTATIC dig_pPlotText_func        (text_bPlotText);
  26. OSTATIC dig_pClear_func            (text_bClear);
  27. OSTATIC dig_pScrollBoxHz_func    (text_bScrollBoxHz);
  28.  
  29. OSTATIC void DIGPRIV text_bReadCharAttrbuf(_arg6(ptd_struct *, opcoord, opcoord, char *, byte *, int));
  30.  
  31. OSTATIC void DIGPRIV bios_clearbox(_arg2(opbox *, opixval));
  32. OSTATIC void DIGPRIV bios_scrollhz(_arg2(opbox *, opcoord));
  33. OSTATIC void DIGPRIV bios_movebuf(_arg5(opcoord, opcoord, opcoord, opcoord, int));
  34. /* -------------------------------------------------------------------------- */
  35.  
  36. boolean pc_ModeBIOS(digp)
  37.     dig_struct *digp;
  38. {
  39.     boolean rval;
  40.  
  41.     if ((rval = pc_OpenBIOS(digp, 0x03)) != 0) {
  42.         return(rval);
  43.     }
  44.     else {
  45.         return(pc_OpenBIOS(digp, 0x07));
  46.     }
  47. }
  48.  
  49. boolean pc_ModeBIOS0(digp)
  50.     dig_struct *digp;
  51. {
  52.     return(pc_OpenBIOS(digp, 0x00));
  53. }
  54.  
  55. boolean pc_ModeBIOS1(digp)
  56.     dig_struct *digp;
  57. {
  58.     return(pc_OpenBIOS(digp, 0x01));
  59. }
  60.  
  61. boolean pc_ModeBIOS2(digp)
  62.     dig_struct *digp;
  63. {
  64.     return(pc_OpenBIOS(digp, 0x02));
  65. }
  66.  
  67. boolean pc_ModeBIOS3(digp)
  68.     dig_struct *digp;
  69. {
  70.     return(pc_OpenBIOS(digp, 0x03));
  71. }
  72.  
  73. boolean pc_ModeBIOS7(digp)
  74.     dig_struct *digp;
  75. {
  76.     return(pc_OpenBIOS(digp, 0x07));
  77. }
  78.  
  79. boolean pc_ModeBIOSEGA43(digp)
  80.     dig_struct *digp;
  81. {
  82.     return(pc_OpenBIOS(digp, PCMODE_EGA43));
  83. }
  84.  
  85. boolean pc_ModeBIOSVGA50(digp)
  86.     dig_struct *digp;
  87. {
  88.     return(pc_OpenBIOS(digp, PCMODE_VGA50));
  89. }
  90. /* -------------------------------------------------------------------------- */
  91.  
  92. static boolean DIGPRIV pc_OpenBIOS(digp, mode)
  93.     dig_struct *digp;
  94.     int mode;
  95. {
  96.     if (!pc_OpenDIG(digp, mode, text_setinfo)) {
  97.         return(FALSE);
  98.     }
  99.     text_setbiosfuncs(digp);
  100.     return(TRUE);
  101. }
  102. /* -------------------------------------------------------------------------- */
  103.  
  104. void text_setbiosfuncs(digp)
  105.     dig_struct *digp;
  106. /*
  107.     Set up the dig function ptrs for text mode BIOS operation.
  108. */
  109. {
  110.     digp->CloseDIG = pc_CloseDIG;
  111.     digp->dControl      = text_bControl;
  112.  
  113.     digp->pPlotText     = text_bPlotText;
  114.     digp->pDrawCursor   = pc_bDrawCursor;
  115.     digp->pClear        = text_bClear;
  116.     digp->pScrollBoxVt  = text_bScrollBoxVt;
  117.     digp->pScrollBoxHz  = text_bScrollBoxHz;
  118.  
  119.     /* in hardware cursor text modes, no pixmap funcs are needed */
  120.     digp->pDrawPixmap   = (dig_pDrawPixmap_func ((*)))pc_dDummy;
  121.     digp->pReadPixmap   = (dig_pReadPixmap_func ((*)))pc_dDummy;
  122.     digp->pControl      = (dig_pControl_func ((*)))pc_dDummy;
  123.  
  124.     digp->vtscroll = TRUE;
  125.     digp->hzscroll = TRUE;
  126.     digp->textfree = FALSE;
  127.     digp->evcheck  = TRUE;
  128.     digp->type = 0;
  129.     digp->version = 0;
  130. }
  131. /* -------------------------------------------------------------------------- */
  132.  
  133. int text_bControl(msg, indata, outdata)
  134.     dig_dcmsg msg;
  135.     VOID *indata;
  136.     VOID *outdata;
  137. {
  138.     switch (msg) {
  139.     case DC_READCHARATTR:
  140.         {    ptarg_struct *pta = (ptarg_struct *)indata;
  141.             text_bReadCharAttrbuf(pta->ptd, pta->x, pta->y,
  142.                                     pta->charbuf, pta->attrbuf, pta->slen);
  143.         }
  144.         break;
  145.     default:
  146.         return(pc_dControl(msg, indata, outdata));
  147.     }
  148.     return(TRUE);
  149. }
  150. /* -------------------------------------------------------------------------- */
  151.  
  152. static void text_bPlotText(ptd, x, y, charbuf, rchar, rattr, slen)
  153.     ptd_struct *ptd;
  154.     opcoord x;
  155.     opcoord y;
  156.     char *charbuf;
  157.     char rchar;
  158.     byte rattr;
  159.     int slen;
  160. /*
  161.     Plot text/attribute buffers to screen at (x,y), clipped into ptd->relboxp.
  162. */
  163. {
  164.     win_type win;
  165.     opbox clipbox;
  166.     int delta;
  167.  
  168.     OREGS regs;
  169.     int orow, ocol;
  170.  
  171.     win = ptd->win;
  172.  
  173.     opbox_copy(&clipbox, ptd->relboxp);
  174.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  175.     x += win_GetXmin(win);
  176.     y += win_GetYmin(win);
  177.  
  178.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  179.     if (slen <= 0) {
  180.         return;
  181.     }
  182.     if (charbuf != NULL) charbuf += delta;
  183.     rattr = pcdata->attrmap[rattr];
  184.  
  185. /* Draw the string, plotting chars and attrs */
  186.     pc_bgetcursorpos(&orow, &ocol);
  187.  
  188.     for ( ; slen > 0; slen--) {
  189.  
  190.     /*    pc_bsetcursorpos(row, x++);   inline instead */
  191.         regs.h.dl = ((byte) x++);        /* set cursor xpos */
  192.         regs.h.dh = ((byte) y-1);        /* set cursor ypos */
  193.         regs.h.ah = VIDINT_SETC;
  194.         regs.h.bh = TEXT_RPAGE;
  195.         oakint86(BIOS_VIDINT, ®s);
  196.  
  197.         if (charbuf != NULL) rchar = *charbuf++;
  198.  
  199.         regs.h.ah = VIDINT_WRTCHAR;
  200.         regs.h.bh = TEXT_RPAGE;
  201.         regs.x.cx = 1;
  202.         regs.h.al = rchar;
  203.         regs.h.bl = rattr;
  204.         oakint86(BIOS_VIDINT, ®s);
  205.     }
  206.     pc_bsetcursorpos(orow, ocol);
  207. }
  208. /* -------------------------------------------------------------------------- */
  209.  
  210. static void text_bClear(ptd, color)
  211.     ptd_struct *ptd;
  212.     opixval color;
  213. {
  214.     win_type win;
  215.     opbox scrbox;
  216.  
  217.     win = ptd->win;
  218.  
  219.     opbox_copy(&scrbox, ptd->relboxp);
  220.     opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
  221.  
  222.     bios_clearbox(&scrbox, color);
  223. }
  224. /* -------------------------------------------------------------------------- */
  225.  
  226. static void text_bScrollBoxHz(ptd, ncols)
  227.     ptd_struct *ptd;
  228.     opcoord ncols;
  229. {
  230.     win_type win;
  231.     opbox scrbox;
  232.  
  233.     win = ptd->win;
  234.  
  235.     opbox_copy(&scrbox, ptd->relboxp);
  236.     opbox_trans(&scrbox, win_GetXmin(win), win_GetYmin(win));
  237.  
  238.     bios_scrollhz(&scrbox, ncols);
  239. }
  240. /* -------------------------------------------------------------------------- */
  241.  
  242. static void DIGPRIV text_bReadCharAttrbuf(ptd, x, y, charbuf, attrbuf, slen)
  243.     ptd_struct *ptd;
  244.     opcoord x;
  245.     opcoord y;
  246.     char *charbuf;
  247.     byte *attrbuf;
  248.     int slen;
  249. {
  250.     win_type win;
  251.     opbox clipbox;
  252.     int delta;
  253.     int orow, ocol;
  254.     OREGS regs;
  255.  
  256.     win = ptd->win;
  257.  
  258.     opbox_copy(&clipbox, ptd->relboxp);
  259.     opbox_trans(&clipbox, win_GetXmin(win), win_GetYmin(win));
  260.     x += win_GetXmin(win);
  261.     y += win_GetYmin(win);
  262.  
  263.     delta = opbox_clipstring(&clipbox, &x, &y, &slen, win_GetFont(win));
  264.     if (slen <= 0) {
  265.         return;
  266.     }
  267.     if (charbuf != NULL) charbuf += delta;
  268.     if (attrbuf != NULL) attrbuf += delta;
  269.  
  270.     if (attrbuf == NULL || charbuf == NULL) {
  271.         return;
  272.     }
  273. /* Read the string, plotting chars and attrs */
  274.     pc_bgetcursorpos(&orow, &ocol);
  275.  
  276.     for ( ; slen > 0; slen--) {
  277.         regs.h.dl = ((byte) x++);        /* set cursor xpos */
  278.         regs.h.dh = ((byte) y-1);        /* set cursor ypos */
  279.         regs.h.ah = VIDINT_SETC;
  280.         regs.h.bh = TEXT_RPAGE;
  281.         oakint86(BIOS_VIDINT, ®s);
  282.  
  283.         regs.h.ah = VIDINT_RDCHAR;
  284.         regs.h.bh = TEXT_RPAGE;
  285.         oakint86(BIOS_VIDINT, ®s);
  286.         *(charbuf++) = regs.h.al;        /* char */
  287.         *(attrbuf++) = regs.h.ah;        /* attr */
  288.     }
  289.     pc_bsetcursorpos(orow, ocol);
  290. }
  291. /* -------------------------------------------------------------------------- */
  292. /* -------------------------------------------------------------------------- */
  293.  
  294. static void DIGPRIV bios_clearbox(scrboxp, color)
  295.     opbox *scrboxp;
  296.     opixval color;
  297. {
  298.     OREGS regs;
  299.  
  300.     regs.h.ah = VIDINT_SCRLDN;
  301.     regs.h.al = 0;
  302.     regs.x.bx = pc_wordcolor(color);    /* bh gets attr */
  303.  
  304.     regs.h.cl = (byte)scrboxp->xmin;
  305.     regs.h.ch = (byte)scrboxp->ymin;
  306.     regs.h.dl = (byte)scrboxp->xmax-1;
  307.     regs.h.dh = (byte)scrboxp->ymax-1;
  308.     oakint86(BIOS_VIDINT, ®s);
  309. }
  310. /* -------------------------------------------------------------------------- */
  311.  
  312. static void DIGPRIV bios_scrollhz(scrboxp, ncols)
  313.     opbox *scrboxp;
  314.     opcoord ncols;
  315. {
  316.     int bwidth;
  317.     opcoord x1, x2;
  318.  
  319.     if (ncols > 0) {
  320.         x1 = scrboxp->xmin + ncols;
  321.         x2 = scrboxp->xmin;
  322.     }
  323.     else if (ncols < 0) {
  324.         ncols = -ncols;
  325.         x1 = scrboxp->xmin;
  326.         x2 = scrboxp->xmin + ncols;
  327.     }
  328.     else return;                                /* quit if no scroll */
  329.  
  330.     if (ncols >= opbox_GetWidth(scrboxp)) return;    /* quit if scroll all */
  331.  
  332.     bwidth = (opbox_GetWidth(scrboxp) - ncols) * 2;
  333.  
  334.     for (;;) {
  335.         bios_movebuf(x1, scrboxp->ymin, x2, scrboxp->ymin, bwidth);
  336.  
  337.         if (opbox_GetHeight(scrboxp) <= 1) {
  338.             break;
  339.         }
  340.         scrboxp->ymin += 1;
  341.     }
  342. }
  343. /* -------------------------------------------------------------------------- */
  344.  
  345. static void DIGPRIV bios_movebuf(x1, y1, x2, y2, bwidth)
  346.     opcoord x1;
  347.     opcoord y1;
  348.     opcoord x2;
  349.     opcoord y2;
  350.     int bwidth;
  351. {
  352.     int orow, ocol;
  353.     OREGS regs;
  354.     byte tchar, tattr;
  355.  
  356. /* Draw the string, plotting chars and attrs */
  357.     pc_bgetcursorpos(&orow, &ocol);
  358.  
  359.     if (x1 < x2) {
  360.         x1 += bwidth/2 - 1;
  361.         x2 += bwidth/2 - 1;
  362.     }
  363.     for ( ; bwidth > 0; bwidth -= 2) {
  364.         regs.h.dl = (byte) x1;        /* set cursor xpos */
  365.         regs.h.dh = (byte) y1;        /* set cursor ypos */
  366.         regs.h.ah = VIDINT_SETC;
  367.         regs.h.bh = TEXT_RPAGE;
  368.         oakint86(BIOS_VIDINT, ®s);
  369.  
  370.         regs.h.ah = VIDINT_RDCHAR;
  371.         regs.h.bh = TEXT_RPAGE;
  372.         oakint86(BIOS_VIDINT, ®s);
  373.         tchar = regs.h.al;        /* char */
  374.         tattr = regs.h.ah;        /* attr */
  375.  
  376.         regs.h.dl = (byte) x2;        /* set cursor xpos */
  377.         regs.h.dh = (byte) y2;        /* set cursor ypos */
  378.         regs.h.ah = VIDINT_SETC;
  379.         regs.h.bh = TEXT_RPAGE;
  380.         oakint86(BIOS_VIDINT, ®s);
  381.  
  382.         regs.h.ah = VIDINT_WRTCHAR;
  383.         regs.h.bh = TEXT_RPAGE;
  384.         regs.x.cx = 1;
  385.         regs.h.al = tchar;        /* char */
  386.         regs.h.bl = tattr;        /* attr */
  387.         oakint86(BIOS_VIDINT, ®s);
  388.         
  389.         if (x1 < x2) {
  390.             x1--;
  391.             x2--;
  392.         }
  393.         else {
  394.             x1++;
  395.             x2++;
  396.         }
  397.     }
  398.     pc_bsetcursorpos(orow, ocol);
  399. }
  400. /* -------------------------------------------------------------------------- */
  401.  
  402.