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

  1.         TITLE    'Listing B-1'
  2.         NAME    ScreenDumpCGA
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        ScreenDumpCGA
  7. ;
  8. ; Function:    Screen Dump for CGA 640x200 2-color and 320x200 4-color modes
  9. ;
  10. ; Caller:    (undefined)
  11. ;
  12. ; Notes:    The main procedure of this program, ScreenDumpCGA, 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, with two horizontal printed pixels
  147. ;    for each vertical pixel in the video buffer.  Since the CGA screen
  148. ;    is 200 pixels high, the printed output is 400 pixels wide.
  149. ;
  150.  
  151. TranslatePixels    PROC    near        ; Caller:    SI = video buffer offset
  152.                     ;        ES:DI -> print buffer
  153.  
  154.         push    ds        ; preserve DS
  155.         mov    ds,VideoBufSeg    ; DS:SI -> video buffer
  156.  
  157.         add    di,398        ; ES:DI -> 2 bytes before end of buffer
  158.  
  159.         mov    cx,200        ; CX := # of vertical pixels
  160.         mov    bx,2000h+1    ; BX := 1st video buffer increment
  161.         mov    dx,81-2000h    ; DX := 2nd video buffer increment
  162.  
  163.         std            ; fill the print buffer backwards
  164.  
  165. L11:        lodsb            ; AL := 8 pixels from video buffer
  166.         mov    ah,al        ; AX := 8 doubled pixels
  167.         stosw            ; write them to print buffer
  168.  
  169.         add    si,bx        ; increment to next interleave of
  170.         xchg    bx,dx        ;  video buffer
  171.  
  172.         loop    L11
  173.  
  174.         cld            ; clear direction flag
  175.         pop    ds        ; restore DS
  176.         ret
  177.  
  178. TranslatePixels    ENDP
  179.  
  180. ;
  181. ; ScreenDumpCGA
  182. ;
  183.  
  184. ScreenDumpCGA    PROC    near        ; Caller:    DS = DGROUP
  185.  
  186.         call    PrinterGraphics    ; configure the printer for graphics
  187.  
  188.         push    ds
  189.         pop    es        ; DS,ES := DGROUP
  190.  
  191.         xor    si,si        ; SI := offset of start of video buffer
  192.  
  193. L21:        push    si
  194.         mov    di,offset DGROUP:PrintBuf
  195.         call    TranslatePixels    ; copy one printable row of pixels
  196.  
  197.         mov    cx,400
  198.         mov    di,offset DGROUP:PrintBuf
  199.         call    PrintPixels    ; print them
  200.  
  201.         pop    si
  202.         inc    si
  203.         cmp    si,80        ; loop across all 80 columns in
  204.         jb    L21        ;  the video buffer
  205.                 
  206.         call    PrinterDefault    ; restore the printer to its default
  207.                     ;  state
  208.         ret
  209.  
  210. ScreenDumpCGA    ENDP
  211.  
  212. _TEXT        ENDS
  213.  
  214.  
  215. _DATA        SEGMENT    word public 'DATA'
  216.  
  217. PrintBuf    DB    400 dup(?)    ; print output buffer
  218.  
  219. VideoBufSeg    DW    0B800h
  220.  
  221. EpsonGraphics    DB    1Bh,33h,18h
  222. EpsonReset    DB    1Bh,40h
  223. DataHeader    DB    1Bh,4Bh,00h,00h
  224. CRLF        DB    0Dh,0Ah
  225.  
  226. _DATA        ENDS
  227.  
  228.         END
  229.