home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / DRIVERS / IBMPC / CGA.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  2KB  |  135 lines

  1. #include    "vogle.h"
  2. #include    <stdio.h>
  3. #ifdef TC
  4. #include    <dos.h>
  5. #define        _dos_allocmem    allocmem
  6. #define        _dos_freemem    freemem
  7. #endif
  8.  
  9. #define        C_PIX_ASPECT    2.4
  10. #define        NPARA    (640 * 200 / 16)
  11.  
  12. static    unsigned    allocated = 0, old_mode;
  13. static    unsigned    char    *backbuf;
  14.  
  15. extern    unsigned    int    _buffer_segment;
  16. extern    unsigned    int    _buffer_offset;
  17. extern    unsigned    int    _cur_color;
  18. static    unsigned    int    save_seg;
  19.  
  20. extern    int    cga_clear(),
  21.         cga_frontbuf(),
  22.         cga_swapbuf(),
  23.         _cga_set_buffer(),
  24.         pc_fill(),
  25.         pc_font(),
  26.         pc_getkey(),
  27.         pc_checkkey(),
  28.         pc_locator(),
  29.         pc_string(),
  30.         setmode();
  31.  
  32.  
  33. cga_init()
  34. {
  35.     vdevice.sizeX = 199 * C_PIX_ASPECT;
  36.     vdevice.sizeY = 199;
  37.     vdevice.sizeSx = 640;
  38.     vdevice.sizeSy = 199;
  39.     vdevice.depth = 1;
  40.     _buffer_segment = 0xB800;
  41.     _buffer_offset = 0;
  42.     _cur_color = 1;
  43.     old_mode = setmode(6);
  44.     pc_locinit(vdevice.sizeSx, vdevice.sizeSy);
  45.     return (1);
  46. }
  47.  
  48. /*
  49.  * cga_exit
  50.  *
  51.  *    Sets the display back to text mode.
  52.  */
  53. cga_exit()
  54. {
  55.     unshowmouse();
  56.     if (allocated)
  57.         _dos_freemem(save_seg);
  58.  
  59.     setmode(old_mode);
  60.     return (1);
  61. }
  62.  
  63. cga_draw(x, y)
  64.     int    x, y;
  65. {
  66.     cgaline(vdevice.cpVx, vdevice.sizeSy - vdevice.cpVy, x, vdevice.sizeSy - y, _cur_color);
  67.     vdevice.cpVx = x;
  68.     vdevice.cpVy = y;
  69. }
  70.  
  71. cga_char(c)
  72.     int    c;
  73. {
  74.     cgachar(c, vdevice.cpVx, vdevice.sizeSy - vdevice.cpVy, _cur_color, 1 - _cur_color);
  75. }
  76.  
  77. cga_color(i)
  78.     int    i;
  79. {
  80.     _cur_color = (i > 0 ? 1 : 0);
  81. }
  82.  
  83. cga_backbuf()
  84. {
  85.     if (!allocated) {
  86.         if (_dos_allocmem(NPARA, &_buffer_segment) != 0)
  87.             verror("cga_backbuf: couldn't allocate space");
  88.  
  89.         allocated = 1;
  90.         save_seg = _buffer_segment;
  91.     }
  92.     return(1);
  93. }
  94.  
  95. static    int
  96. noop()
  97. {
  98.     return (-1);
  99. }
  100.  
  101. static DevEntry cgadev = {
  102.     "cga",
  103.     "large",
  104.     "small",
  105.     cga_backbuf,
  106.     cga_char,
  107.     pc_checkkey,
  108.     cga_clear,
  109.     cga_color,
  110.     cga_draw,
  111.     cga_exit,
  112.     pc_fill,
  113.     pc_font,
  114.     cga_frontbuf,
  115.     pc_getkey,
  116.     cga_init,
  117.     pc_locator,
  118.     noop,
  119.     noop,
  120.     pc_string,
  121.     cga_swapbuf,
  122.     noop
  123. };
  124.  
  125. /*
  126.  * _cga_devcpy
  127.  *
  128.  *    copy the pc device into vdevice.dev.
  129.  */
  130. _cga_devcpy()
  131. {
  132.     vdevice.dev = cgadev;
  133. }
  134.  
  135.