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

  1.         TITLE    'Listing B-2'
  2.         NAME    ScreenDumpEGA
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        ScreenDumpEGA
  7. ;
  8. ; Function:    Screen Dump for EGA 640x350 16-color mode
  9. ;
  10. ; Caller:    (undefined)
  11. ;
  12. ; Notes:    The main procedure of this program, ScreenDumpEGA, may be
  13. ;        called from an application program or as part of a TSR
  14. ;        (Terminate-but-Stay Resident) handler for interrupt 5.
  15. ;
  16.  
  17. STDPRN        =    4        ; MS-DOS standard printer handle
  18.  
  19.  
  20. DGROUP        GROUP    _DATA
  21.  
  22. _TEXT        SEGMENT    byte public 'CODE'
  23.         ASSUME    cs:_TEXT,ds:DGROUP
  24.  
  25. ;
  26. ; PrintLine
  27. ;
  28. ;    Writes one line of characters to the standard printer device.  Ignores
  29. ;    errors.
  30. ;
  31.  
  32. PrintLine    PROC    near        ; Caller:    DS:DX -> data
  33.                     ;        CX = # of bytes
  34.         mov    bx,STDPRN
  35.         mov    ah,40h        ; INT 21h function 40h:  Write
  36.         int    21h
  37.         ret
  38.  
  39. PrintLine    ENDP
  40.  
  41. ;
  42. ; PrinterGraphics
  43. ;
  44. ;    Puts the printer in its "graphics mode."  This routine must be
  45. ;    customized for different printers.
  46. ;
  47.  
  48. PrinterGraphics    PROC    near        ; Configures Epson MX-80 printer
  49.                     ;  for 480 dots/line
  50.  
  51.         mov    dx,offset DGROUP:EpsonGraphics
  52.         mov    cx,3
  53.         call    PrintLine
  54.         ret
  55.  
  56. PrinterGraphics    ENDP
  57.  
  58. ;
  59. ; PrinterDefault
  60. ;
  61. ;    Puts the printer in its default (non-graphics) mode.  Again, this
  62. ;    routine must be customized for different printers.
  63. ;
  64.  
  65. PrinterDefault    PROC    near        ; Configures Epson MX-80 for default
  66.                     ;  alphanumeric output
  67.  
  68.         mov    dx,offset DGROUP:EpsonReset
  69.         mov    cx,2
  70.         call    PrintLine
  71.         ret
  72.  
  73. PrinterDefault    ENDP
  74.  
  75. ;
  76. ; ChopZeroes
  77. ;
  78. ;    Chops trailing zeros from the printer output buffer.
  79. ;
  80.  
  81. ChopZeroes    PROC    near        ; Caller:    ES:DI -> buffer
  82.                     ;        CX = buffer length
  83.                     ; Returns:    CX = adjusted length
  84.  
  85.         jcxz    L01        ; exit if buffer is empty
  86.  
  87.         add    di,cx
  88.         dec    di        ; ES:DI -> last byte in buffer
  89.  
  90.         xor    al,al        ; AL := 0 (byte to scan for)
  91.  
  92.         std            ; scan backwards
  93.         repe    scasb
  94.         cld            ; restore direction flag
  95.         je    L01        ; jump if buffer filled with zeroes
  96.  
  97.         inc    cx        ; adjust length past last nonzero byte
  98.  
  99. L01:        ret
  100.  
  101. ChopZeroes    ENDP
  102.  
  103. ;
  104. ; PrintPixels
  105. ;
  106. ;    Prints one row of pixels on an Epson MX-80.
  107. ;
  108.  
  109. PrintPixels    PROC    near        ; Caller:    DI = offset of buffer
  110.                     ;        CX = buffer length
  111.  
  112.         push    ds
  113.         pop    es        ; ES := DS
  114.  
  115.         push    di        ; preserve buffer offset
  116.         call    ChopZeroes
  117.         push    cx        ; preserve length
  118.  
  119.         mov    word ptr DataHeader+2,cx  ; store buffer length
  120.                           ;  in output data header
  121.         mov    dx,offset DGROUP:DataHeader
  122.         mov    cx,4
  123.         call    PrintLine    ; print data header
  124.  
  125.         pop    cx        ; CX := buffer length
  126.         pop    dx        ; DX := buffer offset
  127.         call    PrintLine    ; print the pixels
  128.  
  129.         mov    dx,offset DGROUP:CRLF
  130.         mov    cx,2
  131.         call    PrintLine
  132.  
  133.         ret
  134.  
  135. PrintPixels    ENDP
  136.  
  137. ;
  138. ; TranslatePixels
  139. ;
  140. ;    Copies one printable row of pixels from the video buffer to the
  141. ;    print buffer.  This routine can be modified at will to change the
  142. ;    scaling or orientation of the printed image, to interpolate gray-
  143. ;    scale values for color pixels, etc.
  144. ;
  145. ;    This routine formats the printer buffer for output to an Epson
  146. ;    MX-80.  The page is printed sideways, so the printed output is
  147. ;    350 pixels wide.
  148. ;
  149.  
  150. TranslatePixels    PROC    near        ; Caller:    SI = video buffer offset
  151.                     ;        ES:DI -> print buffer
  152.  
  153.         push    ds        ; preserve DS
  154.         mov    ds,VideoBufSeg    ; DS:SI -> video buffer
  155.  
  156.         add    di,349        ; ES:DI -> last byte in print buffer
  157.  
  158.         mov    cx,350        ; CX := # of vertical pixels
  159.  
  160. ; set up the Graphics Controller for read mode 1
  161.  
  162.         mov    dx,3CEh        ; Graphics Controller I/O port
  163.         mov    ax,805h        ; AH := 00001000b (read mode 1)
  164.                     ; AL := Mode register number
  165.         out    dx,ax
  166.  
  167.         mov    ax,002        ; AH := 0 (color compare value)
  168.         out    dx,ax        ; AL := Color Compare register number
  169.  
  170.         mov    ax,0F07h    ; AH := 00001111b (color don't care mask)
  171.         out    dx,ax        ; AL := Color Don't Care register number
  172.  
  173. ; fill the print buffer; all nonzero pixels in the video buffer are printed
  174.  
  175.         std            ; fill the print buffer backwards
  176.  
  177. L11:        lodsb            ; AL := 8-pixel color compare value
  178.                     ;  (bits = 0 if pixel <> 0)
  179.         not    al        ; AL := 8 printable pixels
  180.         stosb            ; store in print buffer
  181.  
  182.         add    si,81        ; increment to next row in video buffer
  183.         loop    L11
  184.  
  185.         cld            ; clear direction flag
  186.  
  187. ; restore Graphics Controller default state
  188.  
  189.         mov    ax,5        ; AH := read mode 0, write mode 0
  190.         out    dx,ax        ; AL := Mode register number
  191.  
  192.         mov    ax,7        ; AH := 0 (color don't care mask)
  193.         out    dx,ax        ; AL := Color Don't Care register number
  194.  
  195.         pop    ds        ; restore DS
  196.         ret
  197.  
  198. TranslatePixels    ENDP
  199.  
  200. ;
  201. ; ScreenDumpEGA
  202. ;
  203.  
  204. ScreenDumpEGA    PROC    near        ; Caller:    DS = DGROUP
  205.  
  206.         call    PrinterGraphics    ; configure the printer for graphics
  207.  
  208.         push    ds
  209.         pop    es        ; DS,ES := DGROUP
  210.  
  211.         xor    si,si        ; SI := offset of start of video buffer
  212.  
  213. L21:        push    si
  214.         mov    di,offset DGROUP:PrintBuf
  215.         call    TranslatePixels    ; copy one printable row of pixels
  216.  
  217.         mov    cx,350
  218.         mov    di,offset DGROUP:PrintBuf
  219.         call    PrintPixels    ; print them
  220.  
  221.         pop    si
  222.         inc    si
  223.         cmp    si,80        ; loop across all 80 columns in
  224.         jb    L21        ;  the video buffer
  225.                 
  226.         call    PrinterDefault    ; restore the printer to its default
  227.                     ;  state
  228.         ret
  229.  
  230. ScreenDumpEGA    ENDP
  231.  
  232. _TEXT        ENDS
  233.  
  234.  
  235. _DATA        SEGMENT    word public 'DATA'
  236.  
  237. PrintBuf    DB    350 dup(?)    ; print output buffer
  238.  
  239. VideoBufSeg    DW    0A000h
  240.  
  241. EpsonGraphics    DB    1Bh,33h,18h
  242. EpsonReset    DB    1Bh,40h
  243. DataHeader    DB    1Bh,4Bh,00h,00h
  244. CRLF        DB    0Dh,0Ah
  245.  
  246. _DATA        ENDS
  247.  
  248.         END
  249.