home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SIDEUNIT.ZIP / SIDEUNIT.PAS next >
Encoding:
Pascal/Delphi Source File  |  1989-07-19  |  5.1 KB  |  170 lines

  1. Unit SideUnit;
  2.  
  3. {COPYRIGHT @ 1983
  4.       Jim Holtman
  5.       35 Dogwood Trail
  6.       Randolph, NJ 07869
  7.       (201) 361-3396}
  8.  
  9. {This program will print the `inputfile' sideways on an EPSON MX-80 Printer.
  10.  It makes use of the characters in the PC's ROM for the graphics mode of
  11.  the CRT. The characters in the file are `looked up' and then the graphics
  12.  mode of the printer is used for output.}
  13.  
  14. {This program has been updated and made into a unit for use with Turbo Pascal
  15.  4.0.  Minor changes have been made in the code to account for syntax
  16.  differences, the basic logic of the program has not been altered.
  17.  This revised version has been tested with an AT&T 478T, an IBM
  18.  ProPrinter and an IBM Graphics Printer. Katherine Degerberg}
  19.  
  20.  
  21. interface
  22. uses
  23.     Printer,Crt;
  24.  
  25. Function SideWays(FileName : String;IBM : Boolean):Boolean;
  26.  
  27. implementation
  28.  
  29. { Exist checks for the existence of a file }
  30. Function Exist(FileN: string): Boolean;
  31. Var
  32.     F  : File;
  33.     Ok : Boolean;
  34. begin
  35.    {$I-}
  36.    ASSIGN(F,FileN);  RESET(f);
  37.    Ok := (IOResult = 0);
  38.    If not (Ok) then
  39.       Exist := False
  40.    else
  41.    begin
  42.       Close(f);
  43.       Exist := True;
  44.    end;
  45.    {$I+}
  46. end;  {Exist}
  47.  
  48. Function SideWays(FileName : String;IBM : Boolean):Boolean;
  49. const
  50.     KEEPCHAR : set of char = [^I,' '..'~'];   {Allowed Characters}
  51.     MAX_LINES         = 48;                   {Lines/Page}
  52.     SPACES_PER_LETTER = 8;                    {DOT size of characters}
  53.     SPACES_PER_LINE   = 2;                    {2/72th inch space between lines}
  54.     TAB               = ^I;
  55. type
  56.     vstr = array[0..2000] of char;
  57.     VstrPtr = ^Vstr;
  58.     CHAR_PER_LINE = 0..2000;            {Maximum input line size}
  59.  
  60. var
  61.     ch       : char;
  62.     done     : boolean;
  63.     lptr     : array[1..MAX_LINES] of VStrPtr; {input lines}
  64.     size     : array[1..MAX_LINES] of word;
  65.     inbuf    : array [CHAR_PER_LINE] of char;
  66.     linesize : CHAR_PER_LINE;
  67.     indx     : 0..MAX_LINES;
  68.     line     : byte;
  69.     inputfile   : text;
  70.     col      : CHAR_PER_LINE;
  71.     pchar    : integer;
  72.     ichar    : 0..7;
  73.     max      : CHAR_PER_LINE;
  74.  
  75.         { The absolute address of the rom array maps to the CRT character
  76.            generation matrix in the BIOS. }
  77.  
  78.     rom : array[0..32000] of char absolute $F000:$FA6E;
  79.  
  80.  
  81. begin
  82.  
  83.   if Exist(FileName) then
  84.   begin
  85.  
  86.     for indx := 1 to MAX_LINES do
  87.     begin
  88.         lptr[indx] := Nil;
  89.         size[indx] := 0;
  90.     end;
  91.  
  92.     Assign(inputfile,FileName);
  93.     reset(inputfile);
  94.     repeat
  95.         max := 0;
  96.         linesize := 0;
  97.         line := 1;
  98.         Done := False;
  99.         while (line <= MAX_LINES) and (not Done) do
  100.         begin
  101.             read(inputfile,ch);
  102.             if (ch in KeepChar) then
  103.             begin
  104.                 if ch  = TAB then
  105.                 begin
  106.                    repeat              {Expand TABs}
  107.                            Inc(linesize);
  108.                            inbuf[linesize] := ' ';
  109.                    until (linesize mod 8) = 0;
  110.                 end
  111.                 else
  112.                 begin
  113.                     Inc(linesize);
  114.                     inbuf[linesize] := ch;
  115.                 end;
  116.             end;
  117.  
  118.             if Eoln(inputfile) then {check for End-of-Line}
  119.             begin
  120.                 GetMem(lptr[line],linesize+1);  {allocate string storage}
  121.                 Size[line] := linesize;
  122.                 move(inbuf,lptr[line]^,linesize+1); {save}
  123.                 if linesize > max then max := linesize;
  124.                 linesize := 0;
  125.                 Inc(line);
  126.             end;
  127.             if Eof(inputfile) then Done := True;
  128.         end;
  129.  
  130.         if Eof(inputfile) then line := MAX_LINES
  131.         else dec(line);
  132.  
  133.         for col := 1 to max do  { Output collected lines }
  134.         begin
  135.           if IBM then
  136.             write(lst,chr(27)+'A'+chr(SPACES_PER_LETTER)+chr(27)+Chr(50)+chr(27)+'K',
  137.                      chr((line*(8+SPACES_PER_LINE)) mod 256),
  138.                      chr((line*(8+SPACES_PER_LINE)) div 256))
  139.           else
  140.             write(lst,chr(27)+char(51)+Chr(21)+chr(27)+'K',
  141.                      chr((line*(8+SPACES_PER_LINE)) mod 256),
  142.                      chr((line*(8+SPACES_PER_LINE)) div 256));
  143.  
  144.             for indx := line downto 1 do { Scan next column }
  145.             begin
  146.                 {if column pointer is larger than string, output BLANK}
  147.                 if (size[indx] < col) then pchar := ord(' ')
  148.                 else pchar := ord(lptr[indx]^[col]);
  149.  
  150.                 pchar := pchar*8;
  151.                 for ichar := 7 downto 0 do {Pickup character, a line at a time}
  152.                     Write(lst,rom[pchar+ichar]); {from ROM}
  153.                 for ichar := 1 to SPACES_PER_LINE do write(lst,chr(0));
  154.  
  155.             end;
  156.             Writeln(lst);
  157.         end;
  158.  
  159.         for indx := 1 to line do FreeMem(lptr[indx],size[indx]);  {Free up space on HEAP}
  160.         write(lst,#12); { Form Feed }
  161.     until Eof(inputfile);
  162.     SideWays := True;
  163.  end
  164.  else { FileName did not exist }
  165.      Sideways := False;
  166.  
  167. end; { of Function SideWays }
  168.  
  169. end. { of Unit SideUnit }
  170.