home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 5 / 5_12.asm < prev    next >
Encoding:
Assembly Source File  |  1988-08-11  |  2.1 KB  |  105 lines

  1.         TITLE    'Listing 5-12'
  2.         NAME    SetPixel10
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        SetPixel10
  7. ;
  8. ; Function:    Set the value of a pixel in native EGA graphics modes.
  9. ;
  10. ;        *** Write Mode 0, Set/Reset ***
  11. ;
  12. ; Caller:    Microsoft C:
  13. ;
  14. ;            void SetPixel(x,y,n);
  15. ;
  16. ;            int x,y;        /* pixel coordinates */
  17. ;
  18. ;            int n;            /* pixel value */
  19. ;
  20.  
  21. ARGx        EQU    word ptr [bp+4]    ; stack frame addressing
  22. ARGy        EQU    word ptr [bp+6]
  23. ARGn        EQU    byte ptr [bp+8]
  24.  
  25. RMWbits        EQU    18h        ; read-modify-write bits
  26.  
  27.  
  28. _TEXT        SEGMENT    byte public 'CODE'
  29.         ASSUME    cs:_TEXT
  30.  
  31.         EXTRN    PixelAddr10:near
  32.  
  33.         PUBLIC    _SetPixel10
  34. _SetPixel10    PROC    near
  35.  
  36.         push    bp        ; preserve caller registers
  37.         mov    bp,sp
  38.  
  39.         mov    ax,ARGy        ; AX := y
  40.         mov    bx,ARGx        ; BX := x
  41.         call    PixelAddr10    ; AH := bit mask
  42.                     ; ES:BX -> buffer
  43.                     ; CL := # bits to shift left
  44.  
  45. ; set Graphics Controller Bit Mask register
  46.  
  47.         shl    ah,cl        ; AH := bit mask in proper position
  48.         mov    dx,3CEh        ; GC address register port
  49.         mov    al,8        ; AL := Bit Mask register number
  50.         out    dx,ax
  51.  
  52. ; set Graphics Controller Mode register
  53.  
  54.         mov    ax,0005h    ; AL :=  Mode register number
  55.                     ; AH :=  Write Mode 0 (bits 0,1)
  56.                     ;     Read Mode 0 (bit 3)
  57.         out    dx,ax
  58.  
  59. ; set Data Rotate/Function Select register
  60.  
  61.         mov    ah,RMWbits    ; AH := Read-Modify-Write bits
  62.         mov    al,3        ; AL := Data Rotate/Function Select reg
  63.         out    dx,ax
  64.  
  65. ; set Set/Reset and Enable Set/Reset registers
  66.  
  67.         mov    ah,ARGn        ; AH := pixel value
  68.         mov    al,0        ; AL := Set/Reset reg number
  69.         out    dx,ax
  70.  
  71.         mov    ax,0F01h    ; AH := value for Enable Set/Reset (all
  72.                     ;  bit planes enabled)
  73.                     ; AL := Enable Set/Reset reg number
  74.         out    dx,ax
  75.  
  76. ; set the pixel value
  77.  
  78.         or    es:[bx],al    ; load latches during CPU read
  79.                     ; update latches and bit planes during
  80.                     ;  CPU write
  81.  
  82. ; restore default Graphics Controller registers
  83.  
  84.         mov    ax,0FF08h    ; default Bit Mask
  85.         out    dx,ax
  86.  
  87.         mov    ax,0005        ; default Mode register
  88.         out    dx,ax
  89.  
  90.         mov    ax,0003        ; default Function Select
  91.         out    dx,ax
  92.  
  93.         mov    ax,0001        ; default Enable Set/Reset
  94.         out    dx,ax
  95.  
  96.         mov    sp,bp        ; restore caller registers and return
  97.         pop    bp
  98.         ret
  99.  
  100. _SetPixel10    ENDP
  101.  
  102. _TEXT        ENDS
  103.  
  104.         END
  105.