home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter47 / l47-2.asm < prev    next >
Encoding:
Assembly Source File  |  1997-06-18  |  2.0 KB  |  54 lines

  1. ; Mode X (320x240, 256 colors) write pixel routine. Works on all VGAs.
  2. ; No clipping is performed.
  3. ; C near-callable as:
  4. ;
  5. ;    void WritePixelX(int X, int Y, unsigned int PageBase, int Color);
  6.  
  7. SC_INDEX equ    03c4h   ;Sequence Controller Index
  8. MAP_MASK equ    02h     ;index in SC of Map Mask register
  9. SCREEN_SEG equ  0a000h  ;segment of display memory in mode X
  10. SCREEN_WIDTH equ 80     ;width of screen in bytes from one scan line
  11.                         ; to the next
  12.  
  13. parms   struc
  14.         dw      2 dup (?) ;pushed BP and return address
  15. X       dw      ?       ;X coordinate of pixel to draw
  16. Y       dw      ?       ;Y coordinate of pixel to draw
  17. PageBase dw     ?       ;base offset in display memory of page in
  18.                         ; which to draw pixel
  19. Color   dw      ?       ;color in which to draw pixel
  20. parms   ends
  21.  
  22.         .model  small
  23.         .code
  24.         public  _WritePixelX
  25. _WritePixelX    proc    near
  26.         push    bp      ;preserve caller's stack frame
  27.         mov     bp,sp   ;point to local stack frame
  28.  
  29.         mov     ax,SCREEN_WIDTH
  30.         mul     [bp+Y]  ;offset of pixel's scan line in page
  31.         mov     bx,[bp+X]
  32.         shr     bx,1
  33.         shr     bx,1    ;X/4 = offset of pixel in scan line
  34.         add     bx,ax   ;offset of pixel in page
  35.         add     bx,[bp+PageBase] ;offset of pixel in display memory
  36.         mov     ax,SCREEN_SEG
  37.         mov     es,ax   ;point ES:BX to the pixel's address
  38.  
  39.         mov     cl,byte ptr [bp+X]
  40.         and     cl,011b ;CL = pixel's plane
  41.         mov     ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
  42.         shl     ah,cl   ;set only the bit for the pixel's plane to 1
  43.         mov     dx,SC_INDEX ;set the Map Mask to enable only the
  44.         out     dx,ax       ; pixel's plane
  45.  
  46.         mov     al,byte ptr [bp+Color]
  47.         mov     es:[bx],al ;draw the pixel in the desired color
  48.  
  49.         pop     bp      ;restore caller's stack frame
  50.         ret
  51. _WritePixelX    endp
  52.         end
  53.  
  54.