home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / grafik / tpmac / showmcpt.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1994-04-15  |  8.6 KB  |  256 lines

  1. Program ShowMacPaint;
  2. { Display a MacPaint file on the CGA/EGA and hp laserjet .
  3.  Richard Fritzson
  4.  P.O. Box 4033
  5.  Madison WI  53711
  6.  (608) 274-0870
  7.  Fido: 121/90 }
  8. { 5-Minuten-Übertragung nach Turbo7 /jb '94 }
  9.  
  10. Uses Crt, Dos, Printer, Graph3;
  11.  
  12. Procedure Document;
  13. Begin
  14.   WriteLn('This program will display a Macintosh MacPaint file on an IBM color');
  15.   WriteLn('graphics adapter in high resolution mode, or, more usefully, on an');
  16.   WriteLn('IBM Enhanced color graphics display/monitor combination and on a');
  17.   WriteLn('Hewlett Packard LaserJet printer.');
  18.   WriteLn('');
  19.   WriteLn('Because of the rectagular aspect ration of the IBM displays, especially');
  20.   WriteLn('the standard CGA, the image will be stretched vertically, but it should');
  21.   WriteLn('give you some idea of what it looks like. The image printed by the');
  22.   WriteLn('HP Laserjet is typically of excellent quality, with a sqaure aspect');
  23.   WriteLn('ratio and superb resolution of fine lines and single dots.');
  24.   WriteLn;
  25.   WriteLn('To just display:       ShowMcPt  <filename>');
  26.   WriteLn('To display and print:  ShowMcPt  <filename> <HP> <dpi>');
  27.   WriteLn('   where HP is just the literal "HP" and <dpi> is the density');
  28.   WriteLn('   desired: 75, 150 or 300 dpi. Default is 75 dpi.');
  29.   WriteLn;
  30.   WriteLn('Richard Fritzson');
  31.   WriteLn('Madison, WI');
  32.   WriteLn('Fidonet: 121/90');
  33. End;
  34.  
  35.  
  36. Const
  37.     PathLength = 65;
  38.     BufSize    = 32639;          {This buffer size can be reduced,
  39.                                    to as little as 1023, but it must
  40.                                    remain N*128-1}
  41.     PicStart   = 640;            {Where in the macpaint file does the
  42.                                   raster image begin. In Macbinary
  43.                                   format files, it is 640. In straight files
  44.                                   it is 512. Most BBS posted pictures are
  45.                                   Macbinary.}
  46. Type
  47.     FileName= String[PathLength];
  48.  
  49. Var
  50.     InFile     : file;           {Input File}
  51.     InFileName : FileName;
  52.                                  {Input File Buffer}
  53.     Picture    : Array[0..BufSize] of byte;
  54.     BytePtr    : Integer;
  55.     ScreenOf   : Word;           {Base of screen bitmap}
  56.     ScreenPtr  : Word;
  57.     Ega        : Boolean;        {Color display type}
  58.     Hp         : Boolean;        {Write to HP or not}
  59.     Offset     : Integer;
  60.  
  61. {--------------------------------------------------------------------}
  62. Function IMin(X:Integer; Y:Integer): Integer;
  63. Begin
  64.      If X < Y Then IMin := X
  65.      Else          IMin := Y;
  66. End;
  67.  
  68. {--------------------------------------------------------------------}
  69. Function Crtmode : Integer;      {Return current CRT mode}
  70. Var
  71.    Regs       : Registers;
  72. Begin
  73.      With Regs Do Begin
  74.        Ax := $0F00;
  75.        Intr($10,Regs);
  76.        Crtmode := Lo(Ax);
  77.        End;
  78. End;
  79.  
  80. {--------------------------------------------------------------------}
  81. Function NextByte: Byte;        {Get next byte from input file}
  82. Var I : Integer;
  83. Begin
  84.      NextByte := Picture[BytePtr];
  85.      BytePtr := BytePtr + 1;
  86.      If BytePtr > BufSize Then Begin
  87.         BytePtr := 0;
  88.         I := imin((BufSize+1) div 128,filesize(infile)-filepos(infile));
  89.         Blockread(infile,Picture,I);
  90.      End;
  91. End;
  92.  
  93.  
  94. {--------------------------------------------------------------------}
  95. Procedure CleanUp;
  96. Begin
  97.      TextMode(LastMode);                       {Reset Screen}
  98.      If Hp Then                                {Reset Printer}
  99.         Write(Lst, Chr(27), '*rB', Chr(27), 'E');
  100.      Halt;
  101. End;
  102.  
  103. {--------------------------------------------------------------------}
  104. Procedure Openfile;
  105. Var I : Integer;
  106. Begin
  107.      InFileName := Paramstr(1);
  108.      Assign(InFile, InFileName);
  109.      {$I-}
  110.      Reset(InFile);
  111.      {$I+}
  112.      If IOresult <> 0 Then Begin
  113.          Writeln('Can not open file: '+InFileName);
  114.          Close(InFile);
  115.          CleanUp;
  116.      End Else Begin
  117.          BytePtr := BufSize;
  118.          I := NextByte;
  119.          BytePtr := PicStart;                     {Skip lead bytes}
  120.      End;
  121. End;
  122.  
  123. {--------------------------------------------------------------------}
  124. Procedure SetupDisplay;
  125. Var
  126.    Regs       : Registers;
  127.    Dpi        : String[10];
  128. Begin
  129.      Regs.Ax := $0010;    {Make it very high res}
  130.      intr($10,regs);
  131.      If CrtMode = 16 Then Begin
  132.         ScreenOf := $A000;
  133.         Ega := True;
  134.      End Else Begin
  135.           Ega := False;
  136.           HiRes;
  137.           OffSet := 0;
  138.           palette(2);
  139.           hirescolor(0);
  140.           ScreenOf := $B800;
  141.      End;
  142.      If Paramstr(2) <> '' Then Begin
  143.         Hp := True;
  144.         Write(Lst,#27'E');              {Reset Hp}
  145.         Write(Lst,#27'&l1E');           {One line top margin}
  146.         Write(Lst,#27'&l1H');           {Automatic feed}
  147.         Write(Lst,#27'&a50H');          {Offset 50 pixels from}
  148.         Write(Lst,#27'&a+50V');         { both margins}
  149.                                         {Graphics/dpi}
  150.         Dpi := '75';
  151.         If ParamCount > 2 then Dpi := Paramstr(3);
  152.         Write(Lst,#27'*t'+Dpi+'R'#27'*r1A');
  153.      End Else
  154.         Hp := False;
  155. End;
  156.  
  157. {--------------------------------------------------------------------}
  158. Procedure PaintLine;
  159.   Var
  160.     I          : Integer;
  161.     CharCnt    : Integer;
  162.     Cnt        : Integer;
  163.     B          : Byte;
  164.  
  165.     Procedure SendByte(X:Byte);
  166.     {This is the procedure to modify for other printers/displays.
  167.      You can direct the output to another disk file if you have a particular
  168.      format in mind, or to other printers.
  169.  
  170.      I can supply a driver for the XEROX 4045 laser printer, but the quality
  171.      of graphic images on that printer is distinctly inferior to the HP
  172.      Laserjet. For the eight line at a time dot matrix printers you would
  173.      need to buffer bytes here until a full eight lines was available, then
  174.      reorganize and print them.}
  175.  
  176.     Begin
  177.       If Ega Then Begin                      {Display on screen.}
  178.          Mem[ScreenOf:ScreenPtr] := not X;
  179.          ScreenPtr := ScreenPtr + 1;
  180.       End Else Begin
  181.          Mem[ScreenOf:Offset + ScreenPtr] :=  not X;
  182.          ScreenPtr := ScreenPtr + 1;
  183.          If (screenptr mod 80) = 0 Then Begin
  184.             If Offset = 0 Then begin
  185.                offset := offset + 8192;
  186.                screenptr := screenptr - 80;
  187.             End else begin
  188.                offset := 0;
  189.             End;
  190.          End;
  191.       End;
  192.       If Hp Then Write(Lst,Chr(X));          {Display on hp.}
  193.     End;
  194.  
  195.     Procedure InitLine;
  196.     Begin
  197.          If Hp Then Write(Lst, chr(27), '*b80W');
  198.     End;
  199.  
  200. Begin
  201.    {This is the code that deciphers the MacPaint format.}
  202.    If Keypressed Then CleanUp;             {Bailout}
  203.    InitLine;
  204.    Charcnt := 0;                           {MacPaint stores 72 bytes per line}
  205.    While Charcnt < 72 do Begin
  206.       B := NextByte;
  207.       If B > 127 Then Begin                {Repeating Byte Pattern}
  208.          Cnt := 257 - B;
  209.          B := NextByte;
  210.          for I := 1 to Cnt do
  211.              SendByte(B);
  212.       End Else Begin                       {Sequence of Bytes}
  213.          Cnt := B + 1;
  214.          for I := 1 to Cnt do
  215.              SendByte(NextByte);
  216.       End;                                 {End of chunk}
  217.       Charcnt := Charcnt + Cnt;
  218.   End; {of while}
  219.   For I := 1 to 8 Do SendByte(0);          {Fill in 80 column screen}
  220. End;
  221.  
  222. {--------------------------------------------------------------------}
  223. Var
  224.     I,J        : Integer;
  225. Begin
  226.  If ParamCount = 0 Then Begin
  227.     Document;
  228.     Halt;
  229.  End;
  230.  SetUpDisplay;                                  {EGA Hi Res Mode}
  231.  OpenFile;
  232.  ScreenPtr := 0;
  233.  If Ega Then Begin
  234.         For J := 1 to 350 Do PaintLine;         {Draw first half}
  235.         For J := 1 to  92 Do Begin              {Scroll and draw the rest.
  236.                                                  EGA scroll is 4 lines at
  237.                                                  at time for speed.}
  238.               Move(Mem[ScreenOf:320],Mem[ScreenOf:0],28000-320);
  239.               ScreenPtr := ScreenPtr - 320;
  240.               For I := 1 to 4 Do PaintLine;
  241.         End;
  242.  End Else Begin
  243.         For J := 1 to 200 Do PaintLine;         {Draw first half}
  244.         For J := 1 to 260 Do Begin              {Scroll and draw the rest}
  245.               Move(Mem[ScreenOf:80],Mem[ScreenOf:0],8192-80);
  246.               Move(Mem[ScreenOf:8192+80],Mem[ScreenOf:8192],8192-80);
  247.               ScreenPtr := ScreenPtr - 80;
  248.               PaintLine;
  249.               PaintLine;
  250.         End;
  251.  End;
  252.  Close(Infile);                          {Close file}
  253.  ReadLn;                                 {Wait for CR}
  254.  CleanUp;
  255. End.
  256.