home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / dskutl / transf18.ark / TRANSFER.PAS < prev   
Pascal/Delphi Source File  |  1989-09-27  |  10KB  |  329 lines

  1. (*********************************************************)
  2. (*                                                       *)
  3. (* a program to transfer files between cp/m and ms-dos   *)
  4. (* with a cp/m host system                               *)
  5. (*                                                       *)
  6. (* Written by David Koski     1985                       *)
  7. (*            P.O. Box 1078                              *)
  8. (*            Fort Bragg, CA  95437-1078                 *)
  9. (*            707/964-0806                               *)
  10. (*                                                       *)
  11. (* This program is intended for private non-commertial   *)
  12. (* use and is considered to be public domain material    *)
  13. (*                                                       *)
  14. (*********************************************************)
  15. { enhanced versions 1987-1991 by Guenter Radestock }
  16. { (eMail: radest@ira.uka.de, Snail: Guenter Radestock, }
  17. {  irc:   gr                        Lorscherstr. 37 }
  18. {                                   D-W-6700 Ludwigshafen 29 }
  19. {                                   (FRG) ) }
  20. {  }
  21. { Changes from David Koskis original Version 1.1 (or was it 1.2?) }
  22. { o       TRANSFER will use the information in the Boot-Sector of }
  23. {         a DOS-Disk thus allowing to read more disk formats including }
  24. {         ATARI ST TOS disks (rewrite of identify_msdos) }
  25. { o       removed double-stepping code }
  26. { o       do directory writes when writing physically to the DOS-Disk }
  27. { o       now asks before removing all files on empty input }
  28. { o       removed lots of other bugs }
  29. { o       added path command and read from subdirectory }
  30. { Changes since Version 1.5 }
  31. { o       Directory writes are performed only at the end of each }
  32. {         physical Sector under CP/M 2.2 }
  33. { o       A Disk Reset is done before each menu-selected write, }
  34. {         allowing the user to change disks }
  35. { o       sets the timestamp on DOS Files to the creation date of TRANSFER }
  36. { Changes for Version 1.8 }
  37. { o       Added support for CP/M3.  should still work under 2.2 }
  38. {         though I didn't test it yet }
  39. { o       MSDOS Directory will now output the amount of free space }
  40. {         on the DOS-Disk }
  41. {         removed old bug which caused TRANSFER to crash when attempting }
  42. {         to copy zero-byte files from DOS }
  43. { o       SecTrans support may not work anymore now.  can't believe it ever }
  44. {         did anyway. }
  45. { o       can now be interrupted at startup }
  46. { o       added paging to directory and map commands }
  47.  
  48. program Transfer;
  49.  
  50. const
  51.   SecTrans          = false;    { sector translation for bios read/write }
  52.   SO                = 0;        { offset added to sector number          }
  53.  
  54.   MinSector         = 0;
  55.   MaxFATSize        = 5632;
  56.   Vers              = '1.8';    { Version Number }
  57.   cdyear            = 1991;     { Creation Date }
  58.   cdmonth           = 9;
  59.   cdday             = 14;
  60.   SectorSizeMax     = 1024;
  61.   BufferSize        = SectorSizeMax;
  62.   MenuMargin        = 18;
  63.   ClusterSizeMax    = 2048;
  64.   NameSize          = 8;
  65.   TypeSize          = 3;
  66.   First             = true;
  67.   Next              = false;
  68.   EODirectory       = $FF;
  69.   MTDirectory       = 1;
  70.   FoundDir          = 0;
  71.   SectorSize:integer = 512;
  72.  
  73. type
  74.   SizeArray= Array[1..4] of Byte;
  75.   Str20    = string[20];
  76.   Bufr     = array[1..BufferSize] of char;
  77.   CBufr    = array[1..ClusterSizeMax] of char;
  78.   FATarray = array[1..MaxFATSize] of byte;
  79.   FAT_ID   = (Unidentified,ss8spt,ds8spt,ss9spt,ds9spt,B_20);
  80.   NameAry  = array[1..NameSize] of char;
  81.   TypeAry  = array[1..TypeSize] of char;
  82.   NameStr  = string[20];
  83.  
  84.   PC_FCB   = record
  85.     Name:      NameAry;
  86.     Extention: TypeAry;
  87.     Attribute: byte;
  88.     Rsrvd:     array[12..21] of byte;
  89.     Time:      integer;
  90.     Date:      integer;
  91.     ClusterNo: integer;
  92.     FileSize:  SizeArray;
  93.     end;
  94.  
  95.   CpmFCB   = record
  96.     DriveCode: byte;
  97.     Name:      NameAry;
  98.     Extention: TypeAry;
  99.     Extent:    byte;
  100.     S1,S2:     byte;
  101.     RC:        byte;
  102.     Rsrvd:     array[16..31] of byte;
  103.     CR:        byte;
  104.     R0,R1,R2:  byte;
  105.     end;
  106.  
  107.  
  108. var
  109.   CPM_Buf:           array[1..128] of char;
  110.   Done:              boolean;
  111.   Selection:         char;
  112.   I:                 integer;
  113.  
  114.   cpmnew,dosnew:     boolean;
  115.   MS_DOS_Drive:      integer;
  116.   CPM_Drive:         integer;
  117.   CPM_DriveCh:       char;
  118.   Track:             integer;
  119.   Sector:            integer;
  120.  
  121.   SecsPerCluster:    integer;
  122.   FAT:               FATarray;
  123.   FATSize:           integer;
  124.   fatnum: integer;
  125.   RecordsPerSector:  integer;
  126.   DirSecs:           integer;
  127.   NTracks:           integer;
  128.   NSectors:          integer;
  129.   NClusters:         integer;
  130.   Identity:          FAT_ID;
  131.  
  132.   FirstFATSector:    integer;
  133.   FirstDirSector:    integer;           {erster Sektor im Directory}
  134.   FirstDataSector:   integer;
  135.   FirstDataTrack:    integer;
  136.   DirSector:         integer;
  137.   DirTrack:          integer;
  138.   DirSectorCount:    integer;
  139.   DoubleSided:       boolean;
  140.   SingleSided:       boolean;
  141.  
  142.   DOS_FCB:           ^PC_FCB;
  143.   CPM_FCB:           CpmFCB;
  144.   Buffer:            Bufr;
  145.   DirBuffer:         Bufr;
  146.   DirOffset:         integer;
  147.   DirName:           NameStr;
  148.   ClusterBuffer:     CBufr;
  149.   MaxSector:         integer;
  150.   OutFile:           File;
  151.   BiosError:         boolean;
  152.   VolumeName:        boolean;
  153.   SubDirName:        boolean;
  154.  
  155.   pathStr: string [31];         {Pfadname}
  156.   rootSearch: boolean;          {Flag, ob im RootDir gesucht wird}
  157.   dirCluster: integer;          {erster DirectoryCluster falls rootSearch=FALSE}
  158.   cpm3: Boolean;
  159.  
  160.  
  161. {$I TRANS-00.INC}     { bios call function for cpm2.2 and 3.1 }
  162. {$I TRANS-01.INC}     { main menu, read-write for (dos-)sectors and clusters }
  163. {$I TRANS-02.INC}     { identify_msdos, dos- search_first and search_next }
  164. {$I TRANS-03.INC}     { dir_cpm, set msdos path }
  165. {$I TRANS-04.INC}     { write msdos }
  166. {$I TRANS-05.INC}     { read msdos, dir msdos, map msdos }
  167.  
  168.  
  169.  
  170. procedure EraseMS_DOS;
  171. var
  172.   FileName:          Str20;
  173.   Next,I,Err:        integer;
  174.   CPMFile:           File;
  175.   Cl:                integer;
  176.   Stop:              boolean;
  177.   c: CHAR;
  178. begin
  179. IdentifyMS_DOS;
  180. if not (Identity = Unidentified) then
  181.   begin
  182.   ClrScr;
  183.   writeln;
  184.   write('File Name to Erase From MS-DOS: ');
  185.   readln(FileName);
  186.  
  187.   IF filename = '' THEN BEGIN
  188.     write ('Erase all Files (y/n) ?');
  189.     REPEAT
  190.       read (kbd, c);
  191.       c := upcase (c)
  192.     UNTIL (c = 'Y') OR (c = 'N');
  193.     writeln (c);
  194.     Stop := (c = 'N')
  195.   END
  196.   ELSE
  197.     Stop := FALSE;
  198.  
  199.   writeln;
  200.  
  201.   SearchFirst(FileName,Err);
  202.   while volumeName or subDirName do   {Subdir oder VolumeName nicht loeschen}
  203.     searchNext (fileName, err);
  204.  
  205.   if (Err = EODirectory) then
  206.     write('File Not Found, ')
  207.   else begin
  208.     write('Erasing -');
  209.  
  210.     IF NOT stop THEN
  211.       repeat
  212.         writeln;
  213.         for I:= 1 to NameSize do
  214.           if not (DOS_FCB^.Name[I] = ' ') then
  215.             write(DOS_FCB^.Name[I]);
  216.         write('.');
  217.         for I:= 1 to TypeSize do
  218.           write(DOS_FCB^.Extention[I]);
  219.  
  220.         Cl:= DOS_FCB^.ClusterNo;
  221.         if (Cl <= NClusters) then begin
  222.           Next:= Cl;
  223.           repeat
  224.             Cl:= Next;
  225.             Next:= FATPointer(Cl);
  226.             SetFATPointer(Cl,0);
  227.           until ((Next > NClusters) or (Next = 0));
  228.         end;
  229.  
  230.         DOS_FCB^.Name[1]:= #$E5;
  231.         WriteSector(DirSector,DirTrack,addr(DirBuffer));
  232.         SearchNext(FileName,Err);
  233.         while volumeName or subDirName do   {Subdir oder VolumeName nicht loeschen}
  234.           searchNext (fileName, err);
  235.         Stop:= Break;
  236.       until (Err = EODirectory) or Stop;
  237.  
  238.     writeln;
  239.     writeln;
  240.     end;
  241.   if Stop then write('Aborted, ');
  242.   PutFAT;
  243.   Continue;
  244.   end;
  245. end;
  246.  
  247.  
  248. procedure resetPath;
  249. {  Den Pfad vor Schreiboperationen auf die MSDOS}
  250. {  Diskette zuruecksetzen}
  251.  
  252. begin
  253.   if pathStr <> '\' then begin
  254.     pathStr := '\';
  255.     clrscr;
  256.     gotoxy (12,12);
  257.     writeln ('The MS-DOS Directory Path was reset to "\".');
  258.     gotoxy (12,14);
  259.     continue
  260.   end
  261. end;
  262.  
  263.  
  264.  
  265. (********************)
  266. (*                  *)
  267. (*   main program   *)
  268. (*                  *)
  269. (********************)
  270.  
  271.  
  272.  
  273. begin
  274. cpm3 := (bdos(12) >= $30);
  275. ClrScr;
  276. writeln('TRANSFER -   CP/M <--> MSDOS File Conversion Utility');
  277. writeln('----------------------------------------------------');
  278.  
  279. repeat
  280.   biosError := false;
  281.   cpmnew:=true;dosnew:=true;
  282.   gotoxy(1,5);
  283.   write('Which Drive is the MS-DOS Disk in? ');
  284.   read(KBD,Selection);
  285.   if Selection = chr(3) then begin
  286.     write('^C');
  287.     halt;
  288.   end;
  289.   write(upcase(Selection),':');
  290.   MS_DOS_Drive:= ord(upcase(Selection)) - ord('A');
  291.   writeln;
  292.   write('Which drive is the  CP/M  Disk in? ');
  293.   read(KBD,CPM_DriveCh);
  294.   if CPM_DriveCH = chr(3) then begin
  295.     write('^C');
  296.     halt;
  297.   end;
  298.   CPM_DriveCh:= upcase(CPM_DriveCh);
  299.   Write(CPM_DriveCh,':');
  300.   CPM_Drive:= ord(upcase(CPM_DriveCh)) - ord('A');
  301.   BiosSelect(CPM_Drive);
  302. until not BiosError;
  303.  
  304. pathStr := '\';
  305.  
  306. writeln;
  307. {Delay(500);}
  308. done:= false;
  309.  
  310. repeat
  311.   Selection:= MainSelection;
  312.   ClrScr;
  313.  
  314.   case Selection of
  315.     '1': begin resetPath; WriteMS_DOS end;
  316.     '2': ReadMS_DOS;
  317.     '3': DirMS_DOS;
  318.     '4': MapMS_DOS;
  319.     '5': DirCPM;
  320.     '6': begin resetPath; EraseMS_DOS end;
  321.     '7': showboot;
  322.     '8': chDir;
  323.     '9': Done:= True;
  324.     end; (* case *)
  325.  
  326.   until Done;
  327.  
  328. end.
  329.