home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume34 / vesa_lib / part01 / vesa.cpp < prev    next >
C/C++ Source or Header  |  1993-01-10  |  9KB  |  575 lines

  1. /*
  2.  
  3. Written by: Robert C. Pendleton
  4.  
  5. Placed in the public domain by the author.
  6.  
  7. */
  8.  
  9. #include <dos.h>
  10. #include <conio.h>
  11. #include <stdio.h>
  12. #include "ptypes.h"
  13. #include "vesa.h"
  14.  
  15. //---------------------------------------------------
  16. /*
  17.     Static Variables
  18. */
  19.  
  20. static union _REGS reg;
  21. static struct _SREGS sreg;
  22.  
  23. //---------------------------------------------------
  24. /*
  25. */
  26.  
  27. void
  28. setVGAColor(int16 index, int16 r, int16 g, int16 b)
  29. {
  30.    reg.x.ax =0x1010;
  31.  
  32.    reg.x.bx =index;
  33.    reg.h.dh =r;
  34.    reg.h.ch =g;
  35.    reg.h.cl =b;
  36.  
  37.    _int86(0x10, ®, ®);
  38. }
  39.  
  40. //---------------------------------------------------
  41. /*
  42. */
  43.  
  44. void
  45. setVGAPalette(palette *p)
  46. {
  47.    reg.x.ax =0x1012;
  48.    reg.x.bx =0;
  49.    reg.x.cx =256;
  50.  
  51.    sreg.es = _FP_SEG(p);
  52.    reg.x.dx = _FP_OFF(p);
  53.  
  54.  
  55.    _int86x(0x10, ®, ®, &sreg);
  56. }
  57.  
  58. //---------------------------------------------------
  59. /*
  60. */
  61.  
  62. boolean
  63. getVesaInfo(vesaInfo *infoPtr)
  64. {
  65.       reg.x.ax = 0x4f00;
  66.  
  67.     sreg.es = _FP_SEG(infoPtr);
  68.     reg.x.di = _FP_OFF(infoPtr);
  69.  
  70.         _int86x(0x10, ®, ®, &sreg);
  71.  
  72.     if(reg.x.ax != 0x004f)
  73.     {
  74.         return FALSE;
  75.     }
  76.  
  77.     return TRUE;
  78. }
  79.  
  80. //---------------------------------------------------
  81. /*
  82. */
  83.  
  84. void
  85. printVesaInfo(FILE *file, vesaInfo *info)
  86. {
  87.     int16 *mode;
  88.  
  89.     fprintf(file, "name=%c%c%c%c\n", info->vesa[0],
  90.                        info->vesa[1],
  91.                        info->vesa[2],
  92.                        info->vesa[3]);
  93.  
  94.     fprintf(file, "Version %d.%d\n", info->majorMode, info->minorMode);
  95.     fprintf(file, "Vendor %s\n", info->vendorName);
  96.     fprintf(file, "Capabilities %lX\n", info->capabilities);
  97.  
  98.     mode = info->modes;
  99.     while((*mode) != 0xffff)
  100.     {
  101.         fprintf(file, "mode=%x\n", *mode);
  102.         mode++;
  103.     }
  104.     fflush(file);
  105. }
  106.  
  107. //---------------------------------------------------
  108. /*
  109. */
  110.  
  111. boolean
  112. getVesaModeInfo(int16 mode, vesaModeInfo *infoPtr)
  113. {
  114.       reg.x.ax = 0x4f01;
  115.       reg.x.cx = mode;
  116.  
  117.     sreg.es = _FP_SEG(infoPtr);
  118.     reg.x.di = _FP_OFF(infoPtr);
  119.  
  120.         _int86x(0x10, ®, ®, &sreg);
  121.  
  122.     if(reg.x.ax != 0x004f)
  123.     {
  124.         return FALSE;
  125.     }
  126.  
  127.     return TRUE;
  128. }
  129.  
  130. //---------------------------------------------------
  131. /*
  132. */
  133.  
  134. void
  135. printVesaModeInfo(FILE *file, vesaModeInfo *info)
  136. {
  137.     boolean optionalInfo = FALSE;
  138.  
  139. /* mode attributes */
  140.  
  141.     if(info->modeAttr & (1<<0))
  142.     {
  143.         fprintf(file, "supported\n");
  144.     }
  145.     else
  146.     {
  147.         fprintf(file, "not supported\n");
  148.     }
  149.  
  150.     if(info->modeAttr & (1<<1))
  151.     {
  152.         fprintf(file, "optional info\n");
  153.         optionalInfo = TRUE;
  154.     }
  155.     else
  156.     {
  157.         fprintf(file, "no optional info\n");
  158.         optionalInfo = FALSE;
  159.     }
  160.  
  161.     if(info->modeAttr & (1<<2))
  162.     {
  163.         fprintf(file, "BIOS output\n");
  164.     }
  165.     else
  166.     {
  167.         fprintf(file, "no BIOS output\n");
  168.     }
  169.  
  170.     if(info->modeAttr & (1<<3))
  171.     {
  172.         fprintf(file, "color\n");
  173.     }
  174.     else
  175.     {
  176.         fprintf(file, "monochrome\n");
  177.     }
  178.  
  179.     if(info->modeAttr & (1<<4))
  180.     {
  181.         fprintf(file, "graphics\n");
  182.     }
  183.     else
  184.     {
  185.         fprintf(file, "text\n");
  186.     }
  187.  
  188. /* window A attributes */
  189.  
  190.     if(info->windowAAttr & (1<<0))
  191.     {
  192.         fprintf(file, "window A exists\n");
  193.     }
  194.     else
  195.     {
  196.         fprintf(file, "window A does not exist\n");
  197.     }
  198.  
  199.     if(info->windowAAttr & (1<<1))
  200.     {
  201.         fprintf(file, "window A readable\n");
  202.     }
  203.     else
  204.     {
  205.         fprintf(file, "window A not readable\n");
  206.     }
  207.  
  208.     if(info->windowAAttr & (1<<2))
  209.     {
  210.         fprintf(file, "window A writable\n");
  211.     }
  212.     else
  213.     {
  214.         fprintf(file, "window A not writable\n");
  215.     }
  216.  
  217. /* window B attributes */
  218.  
  219.     if(info->windowBAttr & (1<<0))
  220.     {
  221.         fprintf(file, "window B exists\n");
  222.     }
  223.     else
  224.     {
  225.         fprintf(file, "window B does not exist\n");
  226.     }
  227.  
  228.     if(info->windowBAttr & (1<<1))
  229.     {
  230.         fprintf(file, "window B readable\n");
  231.     }
  232.     else
  233.     {
  234.         fprintf(file, "window B not readable\n");
  235.     }
  236.  
  237.     if(info->windowBAttr & (1<<2))
  238.     {
  239.         fprintf(file, "window B writable\n");
  240.     }
  241.     else
  242.     {
  243.         fprintf(file, "window B not writable\n");
  244.     }
  245.  
  246. /* window attributes */
  247.  
  248.     fprintf(file, "window granularity=%d\n", info->windowGranularity);
  249.     fprintf(file, "window size=%d\n", info->windowSize);
  250.     fprintf(file, "window A start seg=%x\n", info->windowAStartSeg);
  251.     fprintf(file, "window B start seg=%x\n", info->windowBStartSeg);
  252.  
  253.     fprintf(file, "positioning function=%p\n", info->posFuncPtr);
  254.  
  255.     fprintf(file, "bytes/scanline=%d\n", info->bytesPerScanLine);
  256.  
  257.     if(optionalInfo)
  258.     {
  259.         fprintf(file, "width =%d\n", info->width);
  260.         fprintf(file, "height=%d\n", info->height);
  261.  
  262.         fprintf(file, "char width =%d\n", (int16)(info->charWidth));
  263.         fprintf(file, "char height=%d\n", (int16)(info->charHeight));
  264.  
  265.         fprintf(file, "number of planes=%d\n", (int16)(info->numberOfPlanes));
  266.         fprintf(file, "bits/pixel=%d\n", (int16)(info->bitsPerPixel));
  267.         fprintf(file, "number of banks=%d\n", (int16)(info->numberOfBanks));
  268.  
  269.         fprintf(file, "memory model=%d\n", (int16)(info->memoryModel));
  270.         fprintf(file, "size of bank=%d\n", (int16)(info->sizeOfBank));
  271.     }
  272.  
  273.     fflush(file);
  274. }
  275.  
  276. //---------------------------------------------------
  277. /*
  278. */
  279.  
  280. boolean
  281. setVesaMode(int16 mode)
  282. {
  283.       reg.x.ax = 0x4f02;
  284.       reg.x.bx = mode;
  285.  
  286.         _int86x(0x10, ®, ®, &sreg);
  287.  
  288.     if(reg.x.ax != 0x004f)
  289.     {
  290.         return FALSE;
  291.     }
  292.  
  293.     return TRUE;
  294. }
  295.  
  296. //---------------------------------------------------
  297. /*
  298. */
  299.  
  300. boolean
  301. getVesaMode(int16 *mode)
  302. {
  303.       reg.x.ax = 0x4f03;
  304.  
  305.         _int86x(0x10, ®, ®, &sreg);
  306.  
  307.       *mode = reg.x.bx;
  308.  
  309.     if(reg.x.ax != 0x004f)
  310.     {
  311.         return FALSE;
  312.     }
  313.  
  314.     return TRUE;
  315. }
  316.  
  317. //---------------------------------------------------
  318. /*
  319. */
  320.  
  321. boolean
  322. getVesaStateSize(uint8 flags, int32 *size)
  323. {
  324.       reg.x.ax = 0x4f04;
  325.     reg.h.dl = 0x00;
  326.     reg.x.cx = flags;
  327.  
  328.         _int86x(0x10, ®, ®, &sreg);
  329.  
  330.       *size = ((int32)reg.x.bx) * 64;
  331.  
  332.     if(reg.x.ax != 0x004f)
  333.     {
  334.         return FALSE;
  335.     }
  336.  
  337.     return TRUE;
  338. }
  339.  
  340. //---------------------------------------------------
  341. /*
  342. */
  343.  
  344. boolean
  345. getVesaState(uint8 flags, uint8 *buffer)
  346. {
  347.       reg.x.ax = 0x4f04;
  348.     reg.h.dl = 0x01;
  349.     reg.x.cx = flags;
  350.  
  351.     sreg.es = _FP_SEG(buffer);
  352.     reg.x.bx = _FP_OFF(buffer);
  353.  
  354.         _int86x(0x10, ®, ®, &sreg);
  355.  
  356.     if(reg.x.ax != 0x004f)
  357.     {
  358.         return FALSE;
  359.     }
  360.  
  361.     return TRUE;
  362. }
  363.  
  364. //---------------------------------------------------
  365. /*
  366. */
  367.  
  368. boolean
  369. setVesaState(uint8 flags, uint8 *buffer)
  370. {
  371.       reg.x.ax = 0x4f04;
  372.     reg.h.dl = 0x02;
  373.     reg.x.cx = flags;
  374.  
  375.     sreg.es = _FP_SEG(buffer);
  376.     reg.x.bx = _FP_OFF(buffer);
  377.  
  378.         _int86x(0x10, ®, ®, &sreg);
  379.  
  380.     if(reg.x.ax != 0x004f)
  381.     {
  382.         return FALSE;
  383.     }
  384.  
  385.     return TRUE;
  386. }
  387.  
  388. //---------------------------------------------------
  389. /*
  390. */
  391.  
  392. boolean
  393. setVesaWinAAddr(uint16 addr)
  394. {
  395.       reg.x.ax = 0x4f05;
  396.     reg.h.bh = 0x00;
  397.     reg.h.bl = 0x00;
  398.     reg.x.dx = addr;
  399.  
  400.         _int86(0x10, ®, ®);
  401.  
  402.     if(reg.x.ax != 0x004f)
  403.     {
  404.         return FALSE;
  405.     }
  406.  
  407.     return TRUE;
  408. }
  409.  
  410. //---------------------------------------------------
  411. /*
  412. */
  413.  
  414. boolean
  415. setVesaWinBAddr(uint16 addr)
  416. {
  417.       reg.x.ax = 0x4f05;
  418.     reg.h.bh = 0x00;
  419.     reg.h.bl = 0x01;
  420.     reg.x.dx = addr;
  421.  
  422.         _int86(0x10, ®, ®);
  423.  
  424.     if(reg.x.ax != 0x004f)
  425.     {
  426.         return FALSE;
  427.     }
  428.  
  429.     return TRUE;
  430. }
  431.  
  432. //---------------------------------------------------
  433. /*
  434. */
  435.  
  436. boolean
  437. getVesaWinAAddr(uint16 *addr)
  438. {
  439.       reg.x.ax = 0x4f05;
  440.     reg.h.bh = 0x01;
  441.     reg.h.bl = 0x00;
  442.  
  443.         _int86(0x10, ®, ®);
  444.  
  445.     *addr = reg.x.dx;
  446.  
  447.     if(reg.x.ax != 0x004f)
  448.     {
  449.         return FALSE;
  450.     }
  451.  
  452.     return TRUE;
  453. }
  454.  
  455. //---------------------------------------------------
  456. /*
  457. */
  458.  
  459. boolean
  460. getVesaWinBAddr(uint16 *addr)
  461. {
  462.       reg.x.ax = 0x4f05;
  463.     reg.h.bh = 0x01;
  464.     reg.h.bl = 0x01;
  465.  
  466.         _int86(0x10, ®, ®);
  467.  
  468.     *addr = reg.x.dx;
  469.  
  470.     if(reg.x.ax != 0x004f)
  471.     {
  472.         return FALSE;
  473.     }
  474.  
  475.     return TRUE;
  476. }
  477.  
  478. //---------------------------------------------------
  479. /*
  480. */
  481.  
  482. boolean
  483. setVesaScanLineLength(uint16 length)
  484. {
  485.       reg.x.ax = 0x4f06;
  486.     reg.h.bl = 0x00;
  487.     reg.x.cx = length;
  488.  
  489.         _int86(0x10, ®, ®);
  490.  
  491.     if(reg.x.ax != 0x004f)
  492.     {
  493.         return FALSE;
  494.     }
  495.  
  496.     return TRUE;
  497. }
  498.  
  499. //---------------------------------------------------
  500. /*
  501. */
  502.  
  503. boolean
  504. getVesaScanLineLength(uint16 *bytesPerScanLine, 
  505.               uint16 *pixelsPerScanLine, 
  506.               uint16 *maxScanLines)
  507. {
  508.       reg.x.ax = 0x4f06;
  509.     reg.h.bl = 0x01;
  510.  
  511.         _int86(0x10, ®, ®);
  512.  
  513.     *bytesPerScanLine = reg.x.bx;
  514.     *pixelsPerScanLine = reg.x.cx;
  515.     *maxScanLines = reg.x.dx;
  516.  
  517.     if(reg.x.ax != 0x004f)
  518.     {
  519.         return FALSE;
  520.     }
  521.  
  522.     return TRUE;
  523. }
  524.  
  525. //---------------------------------------------------
  526. /*
  527. */
  528.  
  529. boolean
  530. setVesaDisplayStart(uint16 pixel, uint16 line)
  531. {
  532.       reg.x.ax = 0x4f07;
  533.     reg.h.bh = 0x00;
  534.     reg.h.bl = 0x00;
  535.  
  536.     reg.x.cx = pixel;
  537.     reg.x.dx = line;
  538.  
  539.         _int86(0x10, ®, ®);
  540.  
  541.     if(reg.x.ax != 0x004f)
  542.     {
  543.         return FALSE;
  544.     }
  545.  
  546.     return TRUE;
  547. }
  548.  
  549. //---------------------------------------------------
  550. /*
  551. */
  552.  
  553. boolean
  554. getVesaDisplayStart(uint16 *pixel, uint16 *line) 
  555. {
  556.       reg.x.ax = 0x4f07;
  557.     reg.h.bh = 0x00;
  558.     reg.h.bl = 0x01;
  559.  
  560.         _int86(0x10, ®, ®);
  561.  
  562.     *pixel = reg.x.cx;
  563.     *line = reg.x.dx;
  564.  
  565.     if(reg.x.ax != 0x004f)
  566.     {
  567.         return FALSE;
  568.     }
  569.  
  570.     return TRUE;
  571. }
  572.  
  573. //---------------------------------------------------
  574.  
  575.