home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / scr12prn.bas < prev    next >
Encoding:
BASIC Source File  |  1994-04-26  |  6.8 KB  |  177 lines

  1. '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  2. '  Msg#: 408                                          Date: 13 Apr 94  00:27:00
  3. '  From: Howard Hull Jr                               Read: Yes    Replied: No 
  4. '    To: Bill Kahl                                    Mark:                     
  5. '  Subj: Screen 12 Dot Matrix  1/2
  6. '──────────────────────────────────────────────────────────────────────────────
  7. 'BK>I am looking for some code to print a VGA screen mode 12 to the epson
  8. 'BK>compatible dot matrix printer.
  9. 'BK>I use Power Basic but MS Basics are fine.
  10. 'BK>BTW Lloyd of PB tech support gave me some code for printing
  11. 'BK>screen 9 & 12 to the laserjet, and screen 9 to the dot matrix
  12. 'BK>unfortunately the screen 12 routine does not work.
  13. 'BK>I must note thes routines are blazing fast and written in PB/Assembler,
  14. 'BK>so they will not help MS basic users generally.
  15. 'BK>Bill
  16. '        Here's a routine I wrote about 6 mo. ago.
  17. 'It will print to whatever device to wish, includeing a File for later
  18. 'printing.
  19.  
  20. 'Just call VGAtoEpson with these options
  21. '   scrn% - current screen mode
  22. '   F$    - File or device name  eg.("LPT1" or "SCREEN.TXT")
  23. '   flip% - print as a negitive (0 = black screen will be white on paper,
  24. '                1 = Black will print black.)
  25. '   border% - character to use for screen modes 9 & 10
  26. '                (0 = none, 255 = solid, etc.)
  27. 'VGAtoEpson will return ExitCode% - 0 if everthing went OK.
  28.  
  29.  
  30. ' ** Code Start ********************
  31.  DECLARE SUB ScreenParams (scrn%, ScreenWidth%, ScreenLength%, NP%)
  32.  DECLARE SUB VGAtoEpson (scrn%, f$, flip%, border%, ExitCode%)
  33. DEFINT A-Z
  34. SCREEN 12
  35. ' draw your graphics and such
  36. Scr% = 12
  37. F$ = "LPT1"
  38. Flip% = 0
  39. Border% = 0
  40. CALL VGAtoEpson (Scr%, F$, Flip%, Border%, ExitCode%)
  41.  
  42.    SUB ScreenParams (scrn%, ScreenWidth%, ScreenLength%, NumPlanes%)
  43.      ' Return the screen dimensions in pixels
  44.      ' and the number of planes.
  45.      ' used internally by VGAtoEpson.
  46.      NumPlanes% = 4          ' Set default values for SCREEN 12
  47.      ScreenWidth% = 640: ScreenLength% = 480
  48.      SELECT CASE scrn%       ' Change values for other SCREEN modes
  49.         CASE 7
  50.            ScreenWidth% = 320: ScreenLength% = 200
  51.         CASE 8
  52.            ScreenLength% = 200
  53.         CASE 9
  54.            ScreenLength% = 350
  55.         CASE 10
  56.            NumPlanes% = 2: ScreenLength% = 350
  57.         CASE 11
  58.            NumPlanes% = 2
  59.      END SELECT
  60.    END SUB
  61.  
  62.    SUB VGAtoEpson (scrn%, fileN$, flip%, border%, ExitCode%) STATIC
  63.    ' Sends the image on SCREEN 7, 8, 9, 10, 11 or 12
  64.    ' to an Epson printer.
  65.    ' Parameters:
  66.    '    scrn%   - SCREEN video mode of screen to print (7 through 12)
  67.    '    fileN$  - Name of file or device to send image to
  68.    '    flip%   - Invert flag (0 = normal, not 0 = invert)
  69.    '    border% - Character to use for border drawing on screens
  70.    '              9 and 10 (0 = none, 255 = solid, etc.)
  71.    ff = FREEFILE
  72.      OPEN fileN$ FOR BINARY AS ff            'Open the output file
  73.      WIDTH #ff, 255
  74.      Esc$ = CHR$(27): crlf$ = CHR$(13) + CHR$(10)
  75.      line$ = Esc$ + "A" + CHR$(8)           'Set printer to 8/72 lpi"
  76.      PUT #ff, , line$
  77.      CALL ScreenParams(scrn%, ScreenWidth%, ScreenLength%, NumPlanes%)
  78.  
  79.      IF ScreenLength% < 480 THEN       ' Figure how many bytes to send
  80.         numbyte% = ScreenLength% * 2 + 16   ' to printer for one
  81.         maxy% = ScreenLength% - 1           '  line of graphics.
  82.      ELSE
  83.         numbyte% = 960: maxy% = 479
  84.      END IF
  85.  
  86.      DEF SEG = &HA000               'Start of EGA/VGA screen memory
  87.      BorderOffset% = (960 - numbyte%) / (2 * 8)
  88.      IF ScreenLength% < 480 THEN
  89.         ' Print top line for border on screens where border will fit
  90.         line$ = SPACE$(BorderOffset%)           '(for margin)
  91.         PUT #ff, , line$
  92.         line$ = Esc$ + "L" + MKI$(numbyte%)
  93.         line$ = line$ + STRING$(numbyte%, border%) + crlf$
  94.         PUT #ff, , line$
  95.      END IF
  96.  
  97.      ' This loop is the horizontal byte location
  98.      colend% = (ScreenWidth% / 8) - 1
  99.      FOR col% = 0 TO colend%
  100.        ' Set the printer up to receive 716 or 960 bytes
  101.        ' of graphics data
  102.        IF ScreenLength% < 480 THEN
  103.           line$ = SPACE$(BorderOffset%)
  104.           PUT #ff, , line$  '(for border)
  105.        END IF
  106.  
  107.        line$ = Esc$ + "L" + MKI$(numbyte%)  '(for init)
  108.        PUT #ff, , line$
  109.        IF ScreenLength% < 480 THEN
  110.           line$ = STRING$(8, border%)
  111.           PUT #ff, , line$    '(for border)
  112.        END IF
  113.  
  114.        '--- This loop is the vertical byte position
  115.        FOR row% = maxy% TO 0 STEP -1
  116.          ' For 4 plane screens (7, 8, 9 and 12) logically OR the blue
  117.          ' plane with the red plane, send that byte, then OR the green
  118.          ' plane with the intensity plane and send that byte.
  119.  
  120.          ' For screens 10 and 11, the video planes are sent directly
  121.          ' to the printer.
  122.          FOR plane% = 0 TO 1                'Plane (* 2) set
  123.            OUT &H3CE, 4: OUT &H3CF, plane%
  124.            place& = row%                   'Figure out screen memory
  125.            place& = place& * (colend% + 1) ' location to read - use
  126.            place& = place& + col%          ' a long to avoid overflow.
  127.            mem% = PEEK(place&)
  128.  
  129.            IF NumPlanes% = 4 THEN ' OR color planes together
  130.               OUT &H3CE, 4: OUT &H3CF, plane% + 2
  131.               mem% = mem% OR PEEK(place&)
  132.            END IF
  133.  
  134.            '--- Flip the byte if need be (inverses printed picture)
  135.            IF flip% <> 0 THEN mem% = 255 - mem%
  136.            line$ = CHR$(mem%): PUT #ff, , line$
  137.  
  138.          NEXT plane%
  139.        NEXT row%
  140.            IN$ = INKEY$ '-- Check for key press
  141.            '-- If key was escape Clear buffer and exit
  142.            IF (IN$) = CHR$(27) THEN
  143.               Can$ = CHR$(24)
  144.               PUT #ff, , Can$          'CLEAR BUFFER
  145.               CLOSE #ff
  146.               ExitCode% = -1
  147.               EXIT SUB
  148.            END IF
  149.  
  150.        line$ = crlf$    ' Default for no border
  151.        IF ScreenLength% < 480 THEN
  152.           line$ = STRING$(8, border%) + crlf$   ' Righthand border
  153.        END IF
  154.        PUT #ff, , line$
  155.      NEXT col%
  156.  
  157.      IF ScreenLength% < 480 THEN     '--- Print bottom line for border
  158.         line$ = SPACE$(BorderOffset%)       '(for margin)
  159.         PUT #ff, , line$
  160.         line$ = Esc$ + "L" + MKI$(numbyte%)
  161.         line$ = line$ + STRING$(numbyte%, border%) + crlf$
  162.         PUT #ff, , line$
  163.      END IF
  164.      ResetPrn$ = Esc$ + "@"
  165.      PUT #ff, , ResetPrn$                 ' Reset printer
  166.      line$ = CHR$(12): PUT #ff, , line$   ' Send formfeed (page eject)
  167.      CLOSE ff                             ' All done
  168.    END SUB
  169.  
  170. '**** Code End ***************************************
  171.  
  172. '*************************
  173. '* Source code for those of you
  174. '* that want it. Modify to your
  175. '* hearts content. Enjoy.
  176. '*************************
  177.