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

  1.         TITLE    'Listing 5-10'
  2.         NAME    SetPixel06
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        SetPixel06
  7. ;
  8. ; Function:    Set the value of a pixel in 640x200 2-color mode
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            void SetPixel(x,y,n);
  13. ;
  14. ;            int x,y;        /* pixel coordinates */
  15. ;
  16. ;            int n;            /* pixel value */
  17. ;
  18.  
  19. ARGx        EQU    word ptr [bp+4]    ; stack frame addressing
  20. ARGy        EQU    word ptr [bp+6]
  21. ARGn        EQU    byte ptr [bp+8]
  22.  
  23.  
  24. DGROUP        GROUP    _DATA
  25.  
  26. _TEXT        SEGMENT    byte public 'CODE'
  27.         ASSUME    cs:_TEXT,ds:DGROUP
  28.  
  29.         EXTRN    PixelAddr06:near
  30.  
  31.         PUBLIC    _SetPixel06
  32. _SetPixel06    PROC    near
  33.  
  34.         push    bp        ; preserve caller registers
  35.         mov    bp,sp
  36.  
  37.         mov    ax,ARGy        ; AX := y
  38.         mov    bx,ARGx        ; BX := x
  39.         call    PixelAddr06    ; AH := bit mask
  40.                     ; ES:BX -> buffer
  41.                     ; CL := # bits to shift left
  42.  
  43.         mov    al,ARGn        ; AL := unshifted pixel value
  44.         shl    ax,cl        ; AH := bit mask in proper position
  45.                     ; AL := pixel value in proper position
  46.  
  47.         jmp    word ptr SetPixelOp06    ; jump to Replace, AND,
  48.                         ;  OR or XOR routine
  49.  
  50.  
  51.                     ; routine to Replace pixel value
  52.  
  53. ReplacePixel06:    not    ah        ; AH := inverse bit mask
  54.         and    es:[bx],ah    ; zero the pixel value
  55.         or    es:[bx],al    ; set the pixel value
  56.         jmp    short L02
  57.  
  58.  
  59.                     ; routine to AND pixel value
  60. ANDPixel06:    test    al,al
  61.         jnz    L02        ; do nothing if pixel value = 1
  62.  
  63. L01:        not    ah        ; AH := inverse of bit mask
  64.         and    es:[bx],ah    ; set bit in video buffer to 0
  65.         jmp    short L02
  66.                 
  67.  
  68.                     ; routine to OR pixel value
  69. ORPixel06:    test    al,al
  70.         jz    L02        ; do nothing if pixel value = 0
  71.  
  72.         or    es:[bx],al    ; set bit in video buffer
  73.         jmp    short L02
  74.  
  75.  
  76.                     ; routine to XOR pixel value
  77. XORPixel06:    test    al,al
  78.         jz    L02        ; do nothing if pixel value = 0
  79.  
  80.         xor    es:[bx],al    ; XOR bit in video buffer
  81.  
  82.         
  83. L02:        mov    sp,bp        ; restore caller registers and return
  84.         pop    bp
  85.         ret
  86.  
  87. _SetPixel06    ENDP
  88.  
  89. _TEXT        ENDS
  90.  
  91.  
  92. _DATA        SEGMENT    word public 'DATA'
  93.  
  94. SetPixelOp06    dw    ReplacePixel06    ; contains addr of pixel operation
  95.  
  96. _DATA        ENDS
  97.  
  98.         END
  99.