home *** CD-ROM | disk | FTP | other *** search
/ Game Developers Magazine 4 / GDM004.ZIP / SOURCE / PLASPAL / VGA.C < prev    next >
C/C++ Source or Header  |  1994-06-06  |  3KB  |  151 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <mem.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6.  
  7. void    SetGraphicsMode( void );
  8. void    SetTextMode( void );
  9. void    SetDac( char Dac, char Red, char Green, char Blue );
  10. void    GetDac( char Dac, char *Red, char *Green, char *Blue );
  11. void    SetBlock( char Dac, char *Array, char Num );
  12. void    GetBlock( char Dac, char *Array, char Num );
  13. void    SetPoint( int X, int Y, unsigned char Color );
  14. void    GetPoint( int X, int Y, unsigned char *Color );
  15.  
  16. char far *screen;        // This is the pointer to the graphics screen
  17.  
  18. void    SetGraphicsMode( void )
  19. {
  20.     asm {
  21.         mov    ax,0x13
  22.     int    0x10
  23.     }
  24.   screen = (char far*)MK_FP( 0xA000, 0 );
  25. }
  26.  
  27. void    SetTextMode( void )
  28. {
  29.     asm {
  30.       mov    ax,0x03
  31.     int    0x10;
  32.     }
  33. }
  34.  
  35. void    SetDac( char Dac, char Red, char Green, char Blue )
  36. {
  37.     asm {
  38.     mov    dh, Red
  39.     mov    ch, Green
  40.     mov    cl, Blue
  41.     mov    ax, 0x1010
  42.     mov    bl, Dac
  43.     int    0x10
  44.     }
  45. }
  46.  
  47. void    GetDac( char Dac, char *Red, char *Green, char *Blue )
  48. {
  49.     asm {
  50.     mov    ax, 0x1015
  51.     mov    bl, Dac
  52.     int    0x10
  53.     }
  54.     *Red   = _DH;
  55.     *Green = _CH;
  56.     *Blue  = _CL;
  57. }
  58.  
  59. void    SetBlock( char Dac, char *Array, char Num )
  60. {
  61.     int AS, AO;
  62.  
  63.     AS = FP_SEG( Array );
  64.   AO = FP_OFF( Array );
  65.  
  66.   asm {
  67.       push es
  68.     mov    ax, AS
  69.     mov    es, ax
  70.     mov    dx, AO
  71.     xor    ch, ch
  72.     mov    cl, Num
  73.     mov ax, 0x1012
  74.     xor    bh, bh
  75.     mov    bl, Dac
  76.     int    0x10
  77.     pop    es
  78.     }
  79. }
  80.  
  81. void    GetBlock( char Dac, char *Array, char Num )
  82. {
  83.     int AS, AO;
  84.  
  85.     AS = FP_SEG( Array );
  86.   AO = FP_OFF( Array );
  87.  
  88.   asm {
  89.       push     es
  90.     mov    ax, AS
  91.     mov    es, ax
  92.     mov    dx, AO
  93.     xor    ch, ch
  94.     mov    cl, Num
  95.     mov    ax, 0x1017
  96.     xor    bh, bh
  97.     mov    bl, Dac
  98.     int    0x10
  99.     pop    es
  100.     }
  101. }
  102.  
  103. void    SetPoint( int X, int Y, unsigned char Color )
  104. {
  105.     asm {
  106.     push     ds            /* Save registers */
  107.     push     bx
  108.     mov    ax,Y                    /* Get the Y value */
  109.     mov    cx,320
  110.     mul    cx                      /* Multiply by 320 */
  111.     mov    bx,X
  112.     add    ax,bx
  113.     mov    bx,ax
  114.     mov    ax,0xA000               /* Get the offset of */
  115.     mov    ds,ax                   /* video memory into DS */
  116.     mov    al, Color
  117.     mov    [ds:bx],al              /* And put the color there */
  118.     pop    bx                      /* Retrieve registers */
  119.     pop    ds
  120.     }
  121. }
  122.  
  123. void    GetPoint( int X, int Y, unsigned char *Color )
  124. {
  125.     asm {
  126.     mov    ax,Y                    /* Get the Y value */
  127.     mov    cx,320
  128.     mul    cx                      /* Multiply by 320 */
  129.     mov    bx,X
  130.     add    ax,bx                   /* Add X Offset */
  131.     push    ax
  132.     mov    ax,0xA000               /* Get the offset of */
  133.     mov    es,ax                   /* video memory into DS */
  134.     pop    bx
  135.     mov    al,es:[bx]              /* Get the color */
  136.     }
  137.   *Color = _AL;
  138. }
  139.  
  140. void VLine( int X, int Ys, int Ye, char Col ) {
  141.     int    pos;
  142.   char *dst;
  143.  
  144.   dst = screen+(Ys*320)+X;
  145.   for ( pos = Ys; pos < Ye; pos++ ) {
  146.     *dst = Col;
  147.     dst += 320;
  148.     }
  149. }
  150.  
  151.