home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / PALETT.ZIP / DAC.ASM < prev    next >
Assembly Source File  |  1994-01-19  |  4KB  |  186 lines

  1. ;===========================================================================
  2. ;  VGA DAC palette changing routines.
  3. ;  Adapted from 'PC Intern' by Michael Tischer.
  4. ;  Copyright (c) 1994 Jeffrey C. Moxon
  5. ;
  6. ;  Notes:
  7. ;    DAC routines work on VGA cards only.  They can be replaced with
  8. ;  calls to INT 0x10 functions 0x1012 and 0x1017, but even when called after
  9. ;  vertical retrace, some monitors exhibit large amounts of flickering.
  10. ;===========================================================================
  11.  
  12. public _setdac        ;VGA only
  13. public _getdac        ;VGA only
  14. public _setborder
  15. public _setvideomode
  16.  
  17. _CODE   SEGMENT  word public 'CODE'
  18.     ASSUME CS:_CODE;
  19.  
  20. ;=  Procedure to set block of DAC registers
  21. ;=  Declare in C as:  void far setdac(int start, int number, union dac *buff);
  22. ;=  buff is a structure of DAC type:
  23. ;=   union dac
  24. ;=           {
  25. ;=    struct
  26. ;=          {
  27. ;=        char red;
  28. ;=        char green;
  29. ;=        char blue;
  30. ;=          } colors;
  31. ;=            char RGB[3];
  32. ;=           };
  33. ;=
  34.  
  35. _setdac        proc    far
  36.  
  37.             push    bp
  38.         mov    bp,sp
  39.  
  40.         mov     dx,03DAH       ;Wait for end of
  41. Vscan:                                 ;vertical rescan
  42.         in      al,dx
  43.         test    al,8
  44.         jne     Vscan
  45.  
  46. Rscan:
  47.         in      al,dx          ;Go to start of rescan
  48.         test    al,8
  49.         je      Rscan
  50.  
  51.  
  52.         mov    dx,03C6H            ;Set Pel mask to 0xFF
  53.         mov    al,0FFH
  54.         out    dx,al
  55.  
  56.         mov    dx,03C8H            ;Load Write address
  57.         mov    al,byte ptr [bp+6]        ;with starting number
  58.         out    dx,al
  59.  
  60.         xor    cx,cx
  61.         mov    dx,03C9H            ;Load dx with register
  62. SetNext:
  63.         les    bx,dword ptr [bp+10]            ;Load al with Red
  64.         mov    al,byte ptr es:[bx]
  65.  
  66.         out    dx,al                ;Set Red
  67.  
  68.         mov    al,byte ptr es:[bx+1]           ;Set Green
  69.         out    dx,al
  70.  
  71.         mov    al,byte ptr es:[bx+2]           ;Set Blue
  72.         out    dx,al
  73.  
  74.         add    word ptr [bp+10],3              ;Move to next DAC
  75.         inc    cx
  76.  
  77.         cmp    cx,word ptr [bp+8]        ;See if we changed
  78.         jl    SetNext                ;enough of them
  79.  
  80.         pop    bp
  81.  
  82.         retf
  83. _setdac        endp
  84.  
  85. ;=  Procedure to read block of DAC registers
  86. ;=  Declare in C as: void far getdac(int color, int num, union dac *buff);
  87. ;=  buff is a structure of DAC type:
  88. ;=   union dac
  89. ;=           {
  90. ;=    struct
  91. ;=          {
  92. ;=        char red;
  93. ;=        char green;
  94. ;=        char blue;
  95. ;=          } colors;
  96. ;=            char RGB[3];
  97. ;=           };
  98. ;=
  99.  
  100.  
  101. _getdac        proc    far
  102.  
  103.         push    bp
  104.         mov    bp,sp
  105.  
  106.         mov    dx,03C7H            ;Load write address
  107.         mov    al,byte ptr [bp+6]        ;with starting number
  108.         out    dx,al
  109.  
  110.         xor    cx,cx
  111.         mov    dx,03C9H                 ;Load dx with data register
  112. ReadNext:
  113.         in    al,dx             ;Retrieve Red color
  114.  
  115.         les    bx,dword ptr [bp+10]     ;Mov color to DAC struct
  116.         mov    byte ptr es:[bx],al
  117.         nop                 ;Wait a bit
  118.  
  119.         in    al,dx                    ;Retrieve Green color
  120.         mov    byte ptr es:[bx+1],al
  121.         nop                 ;Wait a bit
  122.  
  123.         in    al,dx                    ;Retrieve Blue color
  124.         mov    byte ptr es:[bx+2],al
  125.         nop                 ;Wait a bit
  126.  
  127.         add    word ptr [bp+10],3       ;Move to next DAC
  128.         inc    cx
  129.  
  130.         cmp    cx,word ptr [bp+8]     ;Compare index to number
  131.         jl      ReadNext
  132.  
  133.         pop    bp
  134.  
  135.         retf
  136. _getdac        endp
  137.  
  138. ;=
  139. ;=  Procedure to set overscan color
  140. ;=  Declare in C as: void far setborder(unsigned char color);
  141. ;=
  142.  
  143. _setborder      proc  far
  144.  
  145.         push    bp
  146.         mov     bp, sp
  147.  
  148.         mov     bx, [bp + 6]
  149.         xchg    bh, bl          ;Color in bh
  150.         mov     ax, 1001h
  151.         int     10h
  152.  
  153.         mov     sp, bp
  154.         pop     bp
  155.  
  156.         retf
  157.  
  158. _setborder      endp
  159.  
  160. ;=
  161. ;=  Procedure to set video mode
  162. ;=  Declare in C as: void far setvideomode(unsigned char mode);
  163. ;=
  164.  
  165. _setvideomode    proc   far
  166.  
  167.          push   bp
  168.          mov    bp, sp
  169.  
  170.          mov    ax, [bp + 6]
  171.          mov    ah, 0           ;Mode is in AL
  172.          int    10h
  173.  
  174.  
  175.          mov    sp, bp
  176.          pop    bp
  177.  
  178.          retf
  179.  
  180. _setvideomode    endp
  181.  
  182. _CODE  ends
  183.  
  184. END
  185.  
  186.