home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / RTGRAF.ZIP / SOURCE.ZIP / EREAD.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-30  |  7.1 KB  |  205 lines

  1. ;==================================================================
  2. ;
  3. ;
  4. ; eread(x, y, width, height, picture);
  5. ;
  6. ; EREAD   --- read a raster picture
  7. ;       at entry:       BX = y-coordinate
  8. ;                       CX = x-coordinate
  9. ;                       DL = height (# of rows in picture)
  10. ;                       DH = width (# of bytes in picture)
  11. ;                       SI = ptr to picture
  12. ;      This always places a multiple of bytes into the video memory.
  13.  
  14. ;  large parms
  15. pX0    equ     WORD PTR [bp+6]
  16. pY0    equ     WORD PTR [bp+8]
  17. pWide  equ     WORD PTR [bp+10]
  18. pHigh  equ     WORD PTR [bp+12]
  19. pIoffs equ     WORD PTR [bp+14]
  20. pIseg  equ     WORD PTR [bp+16]
  21.  
  22. ;  local stack storage
  23. lHigh  equ     WORD PTR [bp-2]      ; value from image structure-Width
  24. lWide  equ     WORD PTR [bp-4]      ; value from image structure-Height
  25. lPlane equ     BYTE PTR [bp-6]      ; shifted value to indicate plane
  26. lIseg  equ     WORD PTR [bp-8]      ; image segment passed
  27. lHwrk  equ     WORD PTR [bp-10]     ; working copy as scan line are used
  28. lBwide equ     WORD PTR [bp-12]     ; bytes in a scan line
  29. ;
  30.        public _eread
  31.  
  32. _eread   proc far
  33.         push    bp
  34.         mov     bp,sp
  35.         sub     sp,14
  36.  
  37.         pushf
  38.         cld
  39.         push    si
  40.         push    di
  41.         mov     cx,pX0          ; get x
  42.         mov     bx,pY0          ; get y
  43.         mov     dx,pHigh        ; get height
  44.         mov     lHigh,dx
  45.         mov     ax,pWide        ; get width
  46.         mov     lWide,ax
  47.         mov     si,pIoffs       ; get ptr to Images
  48.         ;
  49.         ;
  50.         call    emapxy          ; Will set DI to offset in video memory
  51.         ;
  52.         ;  Compute bit masks for the work on the left and right ends
  53.         ;  that may not be byte aligned in the video memory
  54.         ;
  55.         mov     cx,pX0          ; init shift count
  56.         and     cx,7            ; cl = number of bits to shift up to a byte
  57.         ;
  58.         ;  From here on out, CX is the size of the chunk we are working
  59.         ;  with. It may be 0, which is byte aligned, or more.
  60.         ;
  61. EgaRNotByte:
  62.         ;
  63.         ;  set the segment reg to access the video screen
  64.         ;
  65.         ;  Since this is a read from the video and a write to the data
  66.         ;  memory, we will swap SI & DI (set as video offset) and use
  67.         ;  the DS as source rather that Data.
  68.         ;
  69.         push    es
  70.         mov     es,pIseg
  71.         push    ds
  72.  
  73.         mov     ax,_bytes_per_line ;save this b4 moding DS
  74.         mov     lBwide,ax
  75.  
  76.         mov     ax,_curr_vid_seg
  77.         mov     ds,ax
  78.         xchg    si,di          ; si->video, di->storage area
  79.         ;
  80.         ;  Start by saving off the height and width of the image
  81.         ;
  82.         mov    ax,pWide
  83.         stosw                   ; es:di
  84.         mov    ax,pHigh
  85.         stosw                   ; es:di
  86.         ;
  87.         ;  Now we have to check that both the width and height are
  88.         ;  greater than 0 !!!
  89.         cmp    pWide,0
  90.         jz     EgaRzero         ; zero width
  91.         cmp    pHigh,0
  92.         jz     EgaRzero         ; zero height
  93.         ;
  94.         ; We will always be using the full byte to be read
  95.         ; then play games with the result
  96.         ;
  97.         GR12_BITMASK   0ffh
  98.         ;
  99.         ;  set the plane to be worked on (0..3)
  100.         ;
  101.         mov     lPlane,0       ; init plane counter
  102.         ;
  103. EgaRPlane:
  104.         ; Do the left partial bits
  105.         ;
  106.         push    si              ; save start of image screen ptr
  107.         ;
  108.         ;
  109.         ;  Now the read register of the GRAPHICS controller
  110.         ;
  111.         READ_PLANE  lPlane
  112.  
  113.         mov     ax,lHigh
  114.         mov     lHwrk,ax        ; init height counter
  115.         ;
  116. EgaRPartByte:
  117.         push    si              ; save start of line screen ptr
  118.         mov     bx,lWide
  119.  
  120.         xor     ah,ah           ; init upper bits to zeros   00000000xxxxxxxx
  121.         lodsb                   ; latch current screen data into ega controller
  122.                                 ;                            00000000gg111111
  123.         ;
  124.         ;   Now the fist byte with the partial is in AL
  125.         ;
  126.         xchg    al,ah           ; get bits loaded into AL up into AH
  127.                                 ;                            gg11111100000000
  128.         ;
  129.         ;  Now we are working with byte aligned portion of the scan line
  130.         ;
  131. EgaRFullByte:
  132.         ;  This loop is done for each part of the image line that
  133.         ;  is on a full byte boundry.
  134.         ;
  135.         lodsb                   ; latch next data            gg11111122222222
  136.         ;
  137.         ;  AH contains partial byte, AL contains next byte
  138.         ;
  139.         rol     ax,cl           ; AH is full byte of data    11111122222222gg
  140.         xchg    ah,al           ; data now in AL             222222gg11111122
  141.         ;
  142.         ;  AL contain bits to store, do we store all of it
  143.         sub     bx,8            ; last byte?
  144.         jz      EgaRScanEnd     ; exact match - no more
  145.         js      EgaRLastPart    ; 0<remaining<8 jif yes
  146.         ;
  147.         ;  Store all of it
  148.         stosb                   ; Save the byte              222222gg........
  149.         ;
  150.         ;  Now the byte has been stored, we need to prepare for
  151.         ;  the next byte
  152.         ;
  153.         ror     ah,cl           ; move the unused bit back down to the
  154.                                 ;  lower part of AH          ..222222gg......
  155.         jmp     EgaRFullByte    ; and again
  156.  
  157. EgaRLastPart:
  158.         ;
  159.         ;  Now we handle the bits that were left over in the right
  160.         ;  end of the scan line that is less than 8 bits
  161.         ;  Compute how many are garbage (g)
  162.         ;
  163.         push    cx
  164.         mov     cx,bx           ; remianing count < 8
  165.         neg     cx              ; wcount = number of spare bit at right end
  166.       ; xchg    al,ah           ; put last bits in AL
  167.         shr     al,cl           ; push unwanted off right end
  168.         shl     al,cl           ; bring back up, bringing in 0's
  169.         pop     cx
  170.         ;  Store all of it
  171.  
  172. EgaRScanEnd:
  173.         stosb                   ; Save the byte
  174.  
  175.         pop     si              ; mov  back to start of screen scan line
  176.         add     si,lBwide       ; mov  to next line
  177.         dec     lHwrk           ; last line?
  178.         jnz     EgaRPartByte    ; jif no, do next line
  179.         ;
  180.         ;  Now we have completed one plane of the image.
  181.         ;  Reset the SI pointer to the start of the video image,
  182.         ;  but keep going in the memory image to be written.
  183.         ;  Move on to the next plane as needed.
  184.         ;
  185.         pop     si              ; move back to start of full screen image
  186.         inc     lPlane          ; move to next plane
  187.         test    lPlane,4        ; done?
  188.         jnz     EgaRDone        ;
  189.         jmp     EgaRPlane       ; jif no
  190.  
  191. EgaRzero:
  192.         mov    di,4             ;stored only w=0 h=0
  193.  
  194. EgaRDone:
  195.         mov     ax,di           ; return bytes stored
  196.         pop     ds
  197.         pop     es
  198.         pop     di
  199.         pop     si
  200.         popf
  201.         mov     sp,bp
  202.         pop     bp
  203.         ret
  204. _eread endp
  205.