home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / modex32.zip / RDPIX.ASM < prev    next >
Assembly Source File  |  1994-09-03  |  2KB  |  60 lines

  1.         .386p
  2.         locals
  3.         include pmc.inc
  4.  
  5. ; Mode X (320x240, 256 colors) read pixel routine. Works on all VGAs.
  6. ; No clipping is performed.
  7. ; C near-callable as:
  8. ;    unsigned int ReadPixelX(int X, int Y, unsigned int PageBase);
  9. ;
  10. ; Modified Aug 30, 1994 (ykumanan)
  11. ; ) Made code 32 bit pm (not fully optimized)
  12. ;
  13.  
  14. GC_INDEX equ    03ceh   ;Graphics Controller Index
  15. READ_MAP equ    04h     ;index in GC of the Read Map register
  16. parms   struc
  17.         dd      2 dup (?) ;pushed EBP and return address
  18. X       dd      ?       ;X coordinate of pixel to read
  19. Y       dd      ?       ;Y coordinate of pixel to read
  20. PageBase dd     ?       ;base offset in display memory of page from
  21.                         ; which to read pixel
  22. parms   ends
  23.  
  24.         @dseg
  25.  
  26.         extrn   SCREEN_SEG:dword
  27.         extrn   SCREEN_WIDTH:dword       ;width of screen in bytes from
  28.                                          ; one scan line to the next
  29.  
  30.         ends
  31.  
  32.         @cseg
  33.         public  _ReadPixelX
  34. _ReadPixelX     proc    near
  35.         push    ebp      ;preserve caller's stack frame
  36.         mov     ebp,esp   ;point to local stack frame
  37.  
  38.         mov     eax, [SCREEN_WIDTH]
  39.         mul     [ebp+Y]  ;offset of pixel's scan line in page
  40.         mov     ebx,[ebp+X]
  41.         shr     ebx,2    ;X/4 = offset of pixel in scan line
  42.         add     ebx,eax   ;offset of pixel in page
  43.         add     ebx,[ebp+PageBase] ;offset of pixel in display memory
  44.         add     ebx,[SCREEN_SEG]
  45.  
  46.         mov     ah,byte ptr [ebp+X]
  47.         and     ah,011b ;AH = pixel's plane
  48.         mov     al,READ_MAP ;AL = index in GC of the Read Map reg
  49.         mov     dx,GC_INDEX ;set the Read Map to read the pixel's
  50.         out     dx,ax       ; plane
  51.  
  52.         mov     al,[ebx] ;read the pixel's color
  53.         sub     ah,ah   ;convert it to an unsigned int
  54.  
  55.         pop     ebp      ;restore caller's stack frame
  56.         ret
  57. _ReadPixelX     endp
  58.         ends
  59.         end
  60.