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

  1.         TITLE    'Listing 13-5'
  2.         NAME    SetPixel
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        SetPixel
  7. ;
  8. ; Function:    Set the value of a pixel in native EGA graphics modes.
  9. ;
  10. ; Caller:    Memory-resident routine invoked via interrupt 60H:
  11. ;
  12. ;            mov ax,PixelX       ; pixel x-coordinate
  13. ;            mov bx,PixelY       ; pixel y-coordinate
  14. ;            mov cx,PixelValue  ; pixel value
  15. ;
  16. ; Notes:    - Assemble and link to create SETPIXEL.EXE.
  17. ;        - Execute once to make SetPixel resident in memory and to point
  18. ;           the INT 60H vector to the RAM-resident code.
  19. ;        - Requires MS-DOS version 2.0 or later.
  20. ;
  21.  
  22. RMWbits        EQU    0
  23.  
  24. _TEXT        SEGMENT    byte public 'CODE'
  25.         ASSUME    cs:_TEXT
  26.  
  27.         EXTRN    PixelAddr:near
  28.  
  29.         PUBLIC    SetPixel
  30. SetPixel    PROC    near        ; RAM-resident interrupt 60H handler
  31.  
  32.         sti            ; enable interrupts
  33.         push    ax        ; preserve caller registers on
  34.         push    bx        ;  caller's stack
  35.         push    cx
  36.         push    dx
  37.  
  38.         push    cx        ; preserve pixel value on stack
  39.  
  40.         call    PixelAddr    ; compute pixel address
  41.         shl    ah,cl
  42.  
  43.         mov    dx,3CEh        ; program the Graphics Controller
  44.         mov    al,8        ; AL := Bit Mask register number
  45.         out    dx,ax
  46.  
  47.         mov    ax,0005h
  48.         out    dx,ax
  49.  
  50.         mov    ah,RMWbits    ; AH := Read-Modify-Write bits
  51.         mov    al,3        ; AL := Data Rotate/Function Select reg
  52.         out    dx,ax
  53.  
  54.         pop    ax 
  55.         mov    ah,al        ; AH := pixel value
  56.         mov    al,0
  57.         out    dx,ax
  58.  
  59.         mov    ax,0F01h
  60.         out    dx,ax
  61.  
  62.         or    es:[bx],al    ; set the pixel value
  63.  
  64.         mov    ax,0FF08h    ; restore default Graphics Controller
  65.         out    dx,ax        ;  values
  66.  
  67.         mov    ax,0005
  68.         out    dx,ax
  69.  
  70.         mov    ax,0003
  71.         out    dx,ax
  72.  
  73.         mov    ax,0001
  74.         out    dx,ax
  75.  
  76.         pop    dx        ; restore caller registers and return
  77.         pop    cx
  78.         pop    bx
  79.         pop    ax
  80.         iret
  81.  
  82. SetPixel    ENDP
  83.  
  84. _TEXT        ENDS
  85.  
  86.  
  87. TRANSIENT_TEXT    SEGMENT    para
  88.         ASSUME    cs:TRANSIENT_TEXT,ss:STACK
  89.  
  90. Install        PROC    near
  91.  
  92.         mov    ax,2560h    ; AH := 25H (INT 21H function number)
  93.                     ; AL := 60H (interrupt number)
  94.         mov    dx,seg _TEXT
  95.         mov    ds,dx
  96.         mov    dx,offset _TEXT:SetPixel   ; DS:DX -> interrupt handler
  97.  
  98.         int    21h        ; point INT 60H vector to
  99.                     ;  SetPixel routine
  100.  
  101.         mov    dx,cs        ; DX := segment of start of transient
  102.                     ;  (discardable) portion of program
  103.         mov    ax,es        ; ES := Program Segment Prefix
  104.         sub    dx,ax        ; DX := size of RAM-resident portion
  105.         mov    ax,3100h    ; AH := 31H (INT 21H function number)
  106.                     ; AL := 0 (return code)
  107.         int    21h        ; Terminate but Stay Resident
  108.  
  109. Install        ENDP
  110.  
  111. TRANSIENT_TEXT    ENDS
  112.  
  113. STACK        SEGMENT    para stack 'STACK'
  114.  
  115.         DB    80h dup(?)    ; stack space for transient portion
  116.                     ;  of program
  117. STACK        ENDS
  118.  
  119.         END    Install
  120.