home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_03 / 2n03031a < prev    next >
Text File  |  1991-01-28  |  5KB  |  138 lines

  1. ; SVGALIB.ASM
  2. ; Assembler: MASM 5.1 
  3. ;-------------------------------------------------------------------
  4. ; SuperVGA Library of functions to demonstrate how to work with the
  5. ; ATI VGA Wonder Card in 800 x 600 x 256 mode (63h)
  6. ;
  7. ; The following routines are included in the file
  8. ; C Routines
  9. ; TextMode      - Place the video card into Color Text Mode (co80)
  10. ; SvgaMode      - Place the video card into SVGA 800 x 600 x 256
  11. ; ChkMode       - Check to see if graphic video mode is supported
  12. ; SetPixel      - Set a pixel (x,y) to a Color
  13. ; InvertPixel   - Invert the pixel at (x,y)
  14. ;-------------------------------------------------------------------
  15. ; This file must be compiled with the MASM 5.1 assembler
  16. ; This particular assembler must be used because of the Assembly/C
  17. ; parameter passing mechanism that is supported by this version
  18. ; of the assembler "PROC    x:WORD" syntax 
  19. ;-------------------------------------------------------------------
  20.  
  21. .MODEL MEDIUM,C
  22. .CODE
  23.  
  24. PAGEMSK    equ     0E1h        ;page mask
  25. EXTREG     equ     0010h       ;extended select register
  26. BIOSSEG    equ     0C000h      ;BIOS segment
  27. VGASEG     equ     0A000h      ;VGA segment
  28.  
  29. ; This function is used to set the video card into TextMode
  30. ; (Color 80). The card is set through the BIOS interrupt 
  31. ; function call
  32.  
  33.             PUBLIC  TextMode
  34. TextMode    PROC    
  35.             mov     ah,0       ; Function # and Video Mode   
  36.             mov     al,3h        
  37.             int     10h        ; call BIOS 
  38.             ret
  39. TextMode    ENDP
  40.  
  41.  
  42. ; This function is used to set the video card into 
  43. ; 800 x 600 x 256 (63h). The card is set through the 
  44. ; BIOS interrupt function call
  45.  
  46.             PUBLIC  SvgaMode
  47. SvgaMode    PROC    
  48.             mov     ah,0      ; Function # and Video Mode
  49.             mov     al,63h   
  50.             int     10h       ;call BIOS to do the check
  51.             ret
  52. SvgaMode    ENDP
  53.  
  54.  
  55. ; This function is used to check is the Desired Mode
  56. ; is available for the video adapter. It is not currently 
  57. ; called is the example C program. The card's mode is 
  58. ; check through the BIOS interrupt function call
  59.  
  60.            PUBLIC  ChkMode
  61. ChkMode    PROC    USES es bp, mode:WORD
  62.            mov     ax,mode         ;mode in AX
  63.            mov     ah,12h                   
  64.            mov     bx,5506h                 
  65.            mov     bp,0ffffh                
  66.            int     10h        ;call BIOS to do the check
  67.            mov     ax,bp      ;get return value fro BIOS call
  68.            inc     ax         ;if the mode is supported
  69.            ret
  70. ChkMode    ENDP
  71.  
  72.  
  73.  
  74. ;Set the passed X,Y to color C:  setpixel(x,y,c);
  75.  
  76.            PUBLIC  SetPixel
  77. SetPixel   PROC    x:WORD, y:WORD, c:WORD
  78.        mov     ax,320h        
  79.        mul     y               ;y * 320h
  80.        add     ax,x            ;Add in x so that...
  81.        adc     dx,0            ;DX = page, AX = byte
  82.        mov     bx,ax           ;set BX to byte value
  83.        mov     ax,dx           ;get the page
  84.        mov     ch,al           ;put page in CH
  85.        mov     ax,BIOSSEG      ;point to video bios segment
  86.        mov     es,ax           ;with ES register
  87.        mov     dx,es:[EXTREG]  ;get EXTENDED_REG address
  88.        mov     al,0B2h         
  89.        out     dx,al           ;send it to board
  90.        inc     dl              ;next port address
  91.        in      al,dx           
  92.        mov     ah,al           
  93.        and     ah,PAGEMSK      ;mask off bits
  94.        shl     ch,1            ;align page to bits
  95.        or      ah,ch           ;assert bits
  96.        mov     al,0B2h         
  97.        dec     dl              ;point back to PAGE register
  98.        out     dx,ax           ;set the page
  99.        mov     ax,VGASEG       ;set AX = video segment
  100.        mov     es,ax           
  101.        mov     ax,c            ;color to set
  102.        mov     BYTE PTR es:[bx],al  ;save color in video page
  103.        ret
  104. SetPixel    ENDP
  105.  
  106.  
  107. ;Invert the passed X,Y:  InvertPixel(x,y)
  108.  
  109.                PUBLIC  InvertPixel
  110. InvertPixel    PROC    x:WORD, y:WORD
  111.           mov     ax,320h        
  112.           mul     y              ;y * 320h
  113.           add     ax,x           ;Add in x so that...
  114.           adc     dx,0           ;DX = page, AX = byte
  115.           mov     bx,ax          ;set BX to byte value
  116.           mov     ax,dx          ;get the page
  117.           mov     ch,al          ;put page in CH
  118.           mov     ax,BIOSSEG     ;point to video bios segment
  119.           mov     es,ax          ;with ES register
  120.           mov     dx,es:[EXTREG] ;get EXTENDED_REG address
  121.           mov     al,0B2h        
  122.           out     dx,al          ;send it to board
  123.           inc     dl             ;next port address
  124.           in      al,dx          
  125.           mov     ah,al          
  126.           and     ah,PAGEMSK     ;mask off bits
  127.           shl     ch,1           ;align page to bits
  128.           or      ah,ch          ;assert bits
  129.           mov     al,0B2h        
  130.           dec     dl             ;point back to PAGE register
  131.           out     dx,ax          ;set the page
  132.           mov     ax,VGASEG      ;set AX = video segment
  133.           mov     es,ax
  134.           xor     BYTE PTR es:[bx],0FFh ;invert the byte
  135.           ret
  136. InvertPixel    ENDP
  137.           END              ; End of Code 
  138.