home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_07 / 1n07015a < prev    next >
Text File  |  1990-11-05  |  7KB  |  284 lines

  1.  
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <dos.h>
  7.  
  8. #include "vesa.h"
  9.  
  10. #ifndef MAKEFD
  11. #include "vesa.fd"
  12. #endif
  13.  
  14. short GetSVGAInfo(temp_info)      /* VESA subfunction 00h */
  15. VgaInfoBlock *temp_info;
  16. {
  17.    union REGS vregs_in, vregs_out;
  18.    struct SREGS vseg_regs;
  19.    VgaInfoBlock far *far_vesa_info = (VgaInfoBlock far *) temp_info;
  20.  
  21.    vregs_in.h.ah = SVGA_SUPPORT;
  22.    vregs_in.h.al = SVGA_INFO;
  23.  
  24.    /* Fetch 32-bit address regardless of memory model... */
  25.    vregs_in.x.di = FP_OFF(far_vesa_info);
  26.    vseg_regs.es  = FP_SEG(far_vesa_info);
  27.  
  28.    int86x(VIDEO_INT, &vregs_in, &vregs_out, &vseg_regs);
  29.    if (vregs_out.h.al != SVGA_SUPPORT)
  30.       return ERROR_VESA_NOT_SUPPORTED;
  31.  
  32.    if (memcmp(temp_info->VESASignature, VESA_SIGNATURE,
  33.        strlen(VESA_SIGNATURE)) != 0)
  34.       return ERROR_VESA_NO_SIGNATURE;
  35.  
  36.    return VESA_OK;
  37. }
  38.  
  39.  
  40.  
  41. short GetSVGAModeInfo(svga_mode, temp_mode_info)      /* VESA subfunction 01h */
  42. short svga_mode;
  43. ModeInfoBlock *temp_mode_info;
  44. {
  45.    union REGS vregs_in, vregs_out;
  46.    struct SREGS vseg_regs;
  47.    ModeInfoBlock far *far_mode_info = (ModeInfoBlock far *) temp_mode_info;
  48.  
  49.    vregs_in.h.ah = SVGA_SUPPORT;
  50.    vregs_in.h.al = SVGA_MODE_INFO;
  51.    vregs_in.x.cx = svga_mode;
  52.  
  53.    /* Fetch 32-bit address regardless of memory model... */
  54.    vregs_in.x.di = FP_OFF(far_mode_info);
  55.    vseg_regs.es  = FP_SEG(far_mode_info);
  56.  
  57.    int86x(VIDEO_INT, &vregs_in, &vregs_out, &vseg_regs);
  58.    return vregs_out.x.ax;
  59. }
  60.  
  61.  
  62. /* VESA subfunction 02h */
  63. short SetSVGAMode(svga_mode, dont_clear_video)
  64. short svga_mode;
  65. short dont_clear_video;
  66. {
  67.    union REGS vregs_in, vregs_out;
  68.  
  69.    svga_mode |= dont_clear_video;
  70.    vregs_in.h.ah = SVGA_SUPPORT;
  71.    vregs_in.h.al = SVGA_SET_MODE;
  72.    vregs_in.x.bx = svga_mode;
  73.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  74.    return vregs_out.x.ax;
  75. }
  76.  
  77.  
  78.  
  79. short GetSVGAModeNo(svga_mode_no)      /* VESA subfunction 03h */
  80. short *svga_mode_no;
  81. {
  82.    union REGS vregs_in, vregs_out;
  83.  
  84.    *svga_mode_no = 0;
  85.    vregs_in.h.ah = SVGA_SUPPORT;
  86.    vregs_in.h.al = SVGA_GET_MODE;
  87.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  88.    *svga_mode_no = vregs_out.x.bx;
  89.    return vregs_out.x.ax;
  90. }
  91.  
  92.  
  93.  
  94. /* VESA subfunction 04h, sub-subfunction 00h */
  95. short GetSVGAStateBufferSize(svga_state_flags, num_blocks)
  96. short svga_state_flags;
  97. short *num_blocks;
  98. {
  99.    union REGS vregs_in, vregs_out;
  100.  
  101.    vregs_in.h.ah = SVGA_SUPPORT;
  102.    vregs_in.h.al = SVGA_SAVE_RESTORE;
  103.    vregs_in.h.dl = SVGA_SR_GET_BUFFER_SIZE;
  104.    vregs_in.x.cx = svga_state_flags;
  105.  
  106.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  107.    *num_blocks = vregs_out.x.bx;
  108.    return vregs_out.x.ax;
  109. }
  110.  
  111.  
  112.  
  113. /* VESA subfunction 04h, sub-subfunction 01h */
  114. short SaveSVGAState(svga_state_flags, state_buffer)
  115. short svga_state_flags;
  116. void *state_buffer;
  117. {
  118.    return SVGAStateBufferFunc(svga_state_flags, state_buffer,
  119.       SVGA_SR_SAVE_VIDEO_STATE);
  120. }
  121.  
  122.  
  123.  
  124. /* VESA subfunction 04h, sub-subfunction 02h */
  125. short RestoreSVGAState(svga_state_flags, state_buffer)
  126. short svga_state_flags;
  127. void *state_buffer;
  128. {
  129.    return SVGAStateBufferFunc(svga_state_flags, state_buffer,
  130.       SVGA_SR_RESTORE_VIDEO_STATE);
  131. }
  132.  
  133.  
  134.  
  135. short SVGAStateBufferFunc(svga_state_flags, state_buffer, sub_func)
  136. short svga_state_flags;
  137. void *state_buffer;
  138. short sub_func;
  139. {
  140.    union REGS vregs_in, vregs_out;
  141.    struct SREGS vseg_regs;
  142.    void far *far_state_buffer = (void far *) state_buffer;
  143.  
  144.    vregs_in.h.ah = SVGA_SUPPORT;
  145.    vregs_in.h.al = SVGA_SAVE_RESTORE;
  146.    vregs_in.h.dl = (unsigned char) sub_func;
  147.    vregs_in.x.cx = svga_state_flags;
  148.  
  149.    /* Fetch 32-bit address regardless of memory model... */
  150.    vregs_in.x.bx = FP_OFF(far_state_buffer);
  151.    vseg_regs.es  = FP_SEG(far_state_buffer);
  152.  
  153.    int86x(VIDEO_INT, &vregs_in, &vregs_out, &vseg_regs);
  154.    return vregs_out.x.ax;
  155. }
  156.  
  157.  
  158.  
  159. short SelectSVGAMemoryWindow(window_no, window_pos)
  160. short window_no;
  161. short window_pos;
  162. {
  163.    union REGS vregs_in, vregs_out;
  164.  
  165.    vregs_in.h.ah = SVGA_SUPPORT;
  166.    vregs_in.h.al = SVGA_CPU_VID_WIN;
  167.    vregs_in.h.bh = SVGA_VID_WIN_SELECT;
  168.    vregs_in.h.bl = (unsigned char) window_no;
  169.    vregs_in.x.dx = window_pos;
  170.  
  171.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  172.    return vregs_out.x.ax;
  173. }
  174.  
  175.  
  176.  
  177. short GetSVGAMemoryWindow(window_no, window_pos)
  178. short window_no;
  179. short *window_pos;
  180. {
  181.    union REGS vregs_in, vregs_out;
  182.  
  183.    *window_pos = 0;
  184.    vregs_in.h.ah = SVGA_SUPPORT;
  185.    vregs_in.h.al = SVGA_CPU_VID_WIN;
  186.    vregs_in.h.bh = SVGA_VID_WIN_GET;
  187.    vregs_in.h.bl = (unsigned char) window_no;
  188.  
  189.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  190.    *window_pos = vregs_out.x.dx;
  191.    return vregs_out.x.ax;
  192. }
  193.  
  194.  
  195.  
  196. short SetSVGALogicalLineLen(pixel_width, scan_line_bytes,
  197.                             scan_line_pixels, max_scan_lines)
  198. short pixel_width;
  199. short *scan_line_bytes;
  200. short *scan_line_pixels;
  201. short *max_scan_lines;
  202. {
  203.    return SVGALogicalLineLenFunc(pixel_width, scan_line_bytes,
  204.           scan_line_pixels, max_scan_lines, SVGA_LOG_LINE_SELECT);
  205. }
  206.  
  207.  
  208.  
  209. short GetSVGALogicalLineLen(pixel_width, scan_line_bytes,
  210.                             scan_line_pixels, max_scan_lines)
  211. short pixel_width;
  212. short *scan_line_bytes;
  213. short *scan_line_pixels;
  214. short *max_scan_lines;
  215. {
  216.    return SVGALogicalLineLenFunc(pixel_width, scan_line_bytes,
  217.           scan_line_pixels, max_scan_lines, SVGA_LOG_LINE_GET);
  218. }
  219.  
  220.  
  221.  
  222. short SVGALogicalLineLenFunc(pixel_width, scan_line_bytes,
  223.                             scan_line_pixels, max_scan_lines,
  224.                             sub_func)
  225. short pixel_width;
  226. short *scan_line_bytes;
  227. short *scan_line_pixels;
  228. short *max_scan_lines;
  229. short sub_func;
  230. {
  231.    union REGS vregs_in, vregs_out;
  232.  
  233.    vregs_in.h.ah = SVGA_SUPPORT;
  234.    vregs_in.h.al = SVGA_LOG_LINE_LEN;
  235.    vregs_in.h.bl = (unsigned char) sub_func;
  236.    vregs_in.x.cx = pixel_width;
  237.  
  238.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  239.    *scan_line_bytes = vregs_out.x.bx;
  240.    *scan_line_pixels = vregs_out.x.cx;
  241.    *max_scan_lines = vregs_out.x.dx;
  242.    return vregs_out.x.ax;
  243. }
  244.  
  245.  
  246.  
  247. short SetSVGADisplayStart(first_pixel, first_scan_line)
  248. short first_pixel;
  249. short first_scan_line;
  250. {
  251.    union REGS vregs_in, vregs_out;
  252.  
  253.    vregs_in.h.ah = SVGA_SUPPORT;
  254.    vregs_in.h.al = SVGA_DISP_START;
  255.    vregs_in.h.bl = SVGA_DISP_START_SET;
  256.    vregs_in.h.bh = 0;
  257.    vregs_in.x.cx = first_pixel;
  258.    vregs_in.x.dx = first_scan_line;
  259.  
  260.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  261.    return vregs_out.x.ax;
  262. }
  263.  
  264.  
  265.  
  266. short GetSVGADisplayStart(first_pixel, first_scan_line)
  267. short *first_pixel;
  268. short *first_scan_line;
  269. {
  270.    union REGS vregs_in, vregs_out;
  271.  
  272.    vregs_in.h.ah = SVGA_SUPPORT;
  273.    vregs_in.h.al = SVGA_DISP_START;
  274.    vregs_in.h.bl = SVGA_DISP_START_GET;
  275.    vregs_in.h.bh = 0;
  276.  
  277.    int86(VIDEO_INT, &vregs_in, &vregs_out);
  278.    *first_pixel = vregs_out.x.cx;
  279.    *first_scan_line = vregs_out.x.dx;
  280.    return vregs_out.x.ax;
  281. }
  282.  
  283.  
  284.