home *** CD-ROM | disk | FTP | other *** search
/ TopWare Tools / TOOLS.iso / tools / top1290 / parallel.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-08-30  |  4.9 KB  |  244 lines

  1. (* ----------------------------- *)
  2. (* ------  PARALLEL.PAS -------- *)
  3. (* ----------------------------- *)
  4.  
  5. (* two sources to read and write files with a parallel-connection *)
  6.  
  7.  
  8. (* GetFile - 22.04.91 - MOLINARI Gilles - Turbo Pacal 5.0 MS-DOS
  9. **
  10. ** Receive a file from AMSTRAD CPC by parallel port LPT2:
  11. ** Half-byte transfert.
  12. ** In both way, a line is use for synchro.
  13. **
  14. ** THIS PROGRAM IS FREEWARE **
  15.  
  16. INTERFACE
  17. ---------
  18.  
  19. PC            CPC        Fonction
  20. --------------------------------    --------------------------------
  21. GND    19 ----    19    GND        GND
  22. BUSY    11 <---    1    -STROBE        Synchro (data available)
  23. -ACK    10 <---    8    D6        |
  24. PE    12 <---    7    D5        | Data
  25. SELECT    13 <---    6    D4        |
  26. -ERROR    15 <---    5    D3        |
  27. D0    2  --->    11    BUSY        Synchro (Ready to receive)
  28.  
  29. . CPC -> PC 
  30.  
  31.   port $279      76543210
  32.         ||||+---- ERROR
  33.         |||+----- SELECT
  34.         ||+------ PAPER END
  35.         |+------- ACKNOWLEDGE
  36.         +-------- BUSY
  37.  
  38. . PC -> CPC
  39.  
  40.   port $278    76543210
  41.                +- D0
  42. *)
  43.  
  44. uses
  45.   crt,dos;
  46. type
  47.   t_filename=string[80];
  48. const
  49.   prompt : array[0..3] of string[2] = ('-'^H,'\'^H,'|'^H,'/'^H);
  50. var
  51.   fich:file;
  52.   nomfich:t_filename;
  53.   i,j,nblk:longint;
  54.   buff:array[0..127] of byte;
  55.  
  56.   function decbin(n:integer):string;
  57.   var
  58.     i:integer;
  59.     str:string;
  60.   begin
  61.     str:='';
  62.     for i:=0 to 7 do begin
  63.       if (n and $80)>0 then str:=str+'1' else str:=str+'0';
  64.       n:=n shl 1;
  65.     end;
  66.     decbin:=str;
  67.   end;
  68.  
  69.   function ReadHalfByte:byte;
  70.   var
  71.     i:byte;
  72.     j:integer;
  73.   begin
  74.     port[$278]:=1;                       {Ready for reception}
  75.     j:=0;
  76.     repeat                               {Waiting for half-byte}
  77.       i:=port[$279];
  78.       inc(j);
  79.       write(prompt[j and 3]);
  80.     until i and $80>0;
  81.     port[$278]:=0;                       {Reception OK}
  82.     while port[$279] and $80<>0 do begin {Waiting for CPC to acknoledge}
  83.       inc(j);
  84.       write(prompt[j and 3]);
  85.     end;
  86.     ReadHalfByte:=(i shr 3) and $F;
  87.   end;
  88.  
  89.   function ReadByte:byte;
  90.   var
  91.     i:byte;
  92.   begin
  93.     i:=ReadHalfByte;
  94.     i:=i+ReadHalfByte shl 4;
  95.     ReadByte:=i;
  96.   end;
  97.  
  98.   procedure GetRequest(var str:t_filename;var nblk:longint);
  99.   var
  100.     i,n:integer;
  101.   begin
  102.     str:='';
  103.     n:=ReadByte;
  104.     for i:=1 to n do str:=str+chr(ReadByte);
  105.     nblk:=ReadByte;
  106.     nblk:=nblk+ReadByte shl 8;
  107.     nblk:=nblk+ReadByte shl 16;
  108.     nblk:=nblk+ReadByte shl 24;
  109.   end;
  110.  
  111. begin
  112.   GetRequest(nomfich,nblk);
  113.   assign(fich,nomfich);
  114.   writeln('Receiving file ',nomfich);
  115.   {$I-}
  116.   rewrite(fich,128);
  117.   {$I+}
  118.   i:=IOResult;
  119.   if i>0 then begin
  120.     writeln('Error ',i,' while creating file ',nomfich);
  121.     halt;
  122.   end;
  123.   for i:=1 to nblk do begin
  124.     write(^M'Block ',i,' of ',nblk);
  125.     for j:=0 to 127 do buff[j]:=ReadByte;
  126.     blockwrite(fich,buff,1);
  127.   end;
  128.   writeln;
  129.   close(fich);
  130. end.
  131.  
  132.  
  133. (* ----------------------------- *)
  134.  
  135.  
  136. (* SendFile - 21.04.91 - MOLINARI Gilles - Turbo Pascal 3.00A CP/M 80
  137. **
  138. ** Sending file from CPC6128 to a remote PC running getfile, by // port, with 
  139. ** an half-byte transfert.
  140. **
  141. ** Program was tested under CP/M Plus, not CP/M 2.2
  142. **
  143. ** THIS PROGRAM IS FREEWARE **
  144.  
  145. INTERFACE
  146. ---------
  147.  
  148. . CPC -> PC
  149.  
  150.  port $EFxx 76543210
  151.             ||||+---- bit 0
  152.             |||+----- bit 1
  153.             ||+------ bit 2
  154.         |+------- bit 3
  155.         +-------- Data available
  156.  
  157. . PC -> CPC
  158.  
  159.  port $F5xx 76543210
  160.              +------- Ready to receive
  161. *)
  162.  
  163. program SendFile;
  164. type
  165.   t_filename=string[80];
  166. var
  167.   fich:file;
  168.   buff:array[0..127] of byte;
  169.   i,j,n:byte;
  170.  
  171.   function Pret:boolean;
  172.   var
  173.     i:byte;
  174.   begin
  175.     inline($01/>$f500/$ed/$78/$32/>i);
  176.     Pret:=(i and $40) > 0;
  177.   end;
  178.  
  179.   procedure OutPort(adr:integer;oct:byte);
  180.   begin
  181.     inline($ed/$4b/>adr/$3a/>oct/$ed/$79);
  182.   end;
  183.  
  184.   procedure sendhbyte(doct:byte);
  185.   var
  186.     mot:byte;
  187.   begin
  188.     mot:=(doct shl 3) and $78;
  189.     repeat until Pret;
  190.     OutPort($ef00,mot or $80);
  191.     repeat until not Pret;
  192.     OutPort($ef00,0);
  193.   end;
  194.  
  195.   procedure sendbyte(oct:byte);
  196.   begin
  197.     sendhbyte(oct and $f);
  198.     sendhbyte(oct shr 4);
  199.   end;
  200.  
  201.   procedure sendrequest(str:t_filename;nh,nl:integer);
  202.   var
  203.     i:integer;
  204.   begin
  205.     i:=pos(str,':');
  206.     if i>0 then delete(str,1,i);
  207.     for i:=0 to length(str) do sendbyte(ord(str[i]));
  208.     sendbyte(n and $ff);
  209.     sendbyte(n shr 8);
  210.     sendbyte(nh and $ff);
  211.     sendbyte(nh shr 8);
  212.   end;
  213.  
  214. begin
  215.   if ParamCount<>1 then begin
  216.     writeln('Usage = SENDFILE filename');
  217.     halt;
  218.   end;
  219.   assign(fich,paramstr(1));
  220.   {$I-}
  221.   reset(fich);
  222.   {$I+}
  223.   i:=IOResult;
  224.   if i<>0 then begin
  225.     writeln('Error ',i,' while opening file ',paramstr(1));
  226.     halt;
  227.   end;
  228.   OutPort($32,0);
  229.   i:=0;
  230.   n:=filesize(fich);
  231.   sendrequest(paramstr(1),0,n);
  232.   while not eof(fich) do begin
  233.     i:=i+1;
  234.     write(i,' of ',n,^M);
  235.     blockread(fich,buff,1);
  236.     for j:=0 to 127 do
  237.       sendbyte(buff[j]);
  238.   end;
  239.   clreol;
  240.   close(fich);
  241. end.
  242.  
  243. (* ----------------------------- *)
  244.