home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / TRANS12C.LBR / TRANS128.PAS < prev   
Pascal/Delphi Source File  |  2000-06-30  |  12KB  |  438 lines

  1.  
  2.  
  3. (*********************************************************)
  4. (*                                                       *)
  5. (* TRANSFER.PAS (version 1.0) -                          *)
  6. (* a program to transfer files between cp/m and ms-dos   *)
  7. (* with a cp/m host system                               *)
  8. (*                                                       *)
  9. (* Written by David Koski     1985                       *)
  10. (*            P.O. Box 1078                              *)
  11. (*            Fort Bragg, CA  95437-1078                 *)
  12. (*            707/964-0806                               *)
  13. (*                                                       *)
  14. (* This program is intended for private non-commercial   *)
  15. (* use and is considered to be public domain material    *)
  16. (*                                                       *)
  17. (*********************************************************)
  18. (*                                                       *)
  19. (* TRANS128.PAS (version 1.2C) -                         *)
  20. (* Modified/enhanced for C-128 with single 1571 drive:   *)
  21. (*   Format MS-DOS disks,                                *)
  22. (*   Rename MS-DOS files,                                *)
  23. (*   View MS-DOS text files.                             *)
  24. (*                                                       *)
  25. (*         by B-J Lee         1987                       *)
  26. (*            1021 Merritt Dr.                           *)
  27. (*            Tallahassee, FL 32301                      *)
  28. (*            CompuServe [71171,3260]                    *)
  29. (*                                                       *)
  30. (*********************************************************)
  31.  
  32.  
  33.  
  34. program Transfer;
  35.  
  36. const
  37.   SecTrans          = false;   { sector translation for bios read/write }
  38.   SO                = 0;       { offset added to sector number          }
  39.   DEBUG             = false;
  40.  
  41.   DataBufferSize    = 30720;   { 30 K bytes }
  42.   MinSector         = 0;
  43.   MaxFATSize        = 1024;
  44.   Vers              = '1.2C';
  45.   SectorSizeMax     = 512;
  46.   BufferSize        = SectorSizeMax;
  47.   MenuMargin        = 18;
  48.  {ClusterSizeMax    = 2048;}
  49.   SizePC_FCB        = 32;
  50.   SizeCPM_FCB       = 32;
  51.   NameSize          = 8;
  52.   TypeSize          = 3;
  53.   First             = true;
  54.   Next              = false;
  55.   EODirectory       = $FF;
  56.   MTDirectory       = 1;
  57.   FoundDir          = 0;
  58.  
  59.   SELDSK            = 9;        { BIOS calls for CP/M+ }
  60.   SETTRK            = 10;
  61.   SETSEC            = 11;
  62.   SETDMA            = 12;
  63.   RDSEC             = 13;
  64.   WRSEC             = 14;
  65.   SECTRAN           = 16;
  66.   DEVTBL            = 20;
  67.   DRVTBL            = 22;
  68.   FLUSH             = 24;
  69.   USERFUN           = 30;
  70.  
  71.   GETVSN            = 12;       { BDOS calls }
  72.   RESETDSK          = 13;
  73.   LOGDSK            = 14;
  74.   SearchF           = 17;
  75.   SearchN           = 18;
  76.   CURDSK            = 25;
  77.   SetDMAF           = 26;
  78.   SETATT            = 30;
  79.   COMPUTESIZE       = 35;
  80.   CALLBIOS          = 50;
  81.  
  82. type
  83.   SizeArray= Array[1..4] of Byte;
  84.   Str20    = string[20];
  85.   Bufr     = array[1..BufferSize] of char;
  86.  {CBufr    = array[1..ClusterSizeMax] of char;}
  87.   FATarray = array[1..MaxFATSize] of byte;
  88.   FAT_ID   = (Unidentified,ss8spt,ds8spt,ss9spt,ds9spt,B_20);
  89.   NameAry  = array[1..NameSize] of char;
  90.   TypeAry  = array[1..TypeSize] of char;
  91.   NameStr  = string[20];
  92.  
  93.   PC_FCB   = record
  94.     Name:      NameAry;
  95.     Extention: TypeAry;
  96.     Attribute: byte;
  97.     Rsrvd:     array[12..21] of byte;
  98.     Time:      integer;
  99.     Date:      integer;
  100.     ClusterNo: integer;
  101.     FileSize:  SizeArray;
  102.     end;
  103.  
  104.   CpmFCB   = record
  105.     DriveCode: byte;     {0=default, 1=A, 2=B...}
  106.     Name:      NameAry;
  107.     Extention: TypeAry;
  108.     Extent:    byte;
  109.     S1,S2:     byte;
  110.     RC:        byte;
  111.     Rsrvd:     array[16..31] of byte;
  112.     CR:        byte;
  113.     R0,R1,R2:  byte;
  114.     end;
  115. var
  116.   CPMversion:        integer;
  117.   CPM_Buf:           array[1..128] of char;
  118.   Done:              boolean;
  119.   Selection:         char;
  120.   I:                 integer;
  121.  
  122.   DefaultDisk:       integer;
  123.   MS_DOS_Drive:      integer;
  124.   CPM_Drive:         integer;
  125.   CPM_DriveCh:       char;
  126.   Track:             integer;
  127.   Sector:            integer;
  128.  
  129.   SecsPerCluster:    integer;
  130.   FAT:               FATarray;
  131.   FATSize:           integer;
  132.   SectorSize:        integer;
  133.   RecordsPerSector:  integer;
  134.   DirSecs:           integer;
  135.   NTracks:           integer;
  136.   NSectors:          integer;
  137.   NClusters:         integer;
  138.   Identity:          FAT_ID;
  139.  
  140.   FirstFATSector:    integer;
  141.   FirstDirSector:    integer;
  142.   FirstDataSector:   integer;
  143.   FirstDataTrack:    integer;
  144.   DirSector:         integer;
  145.   DirTrack:          integer;
  146.   DirSectorCount:    integer;
  147.   SingleSided:       boolean;
  148.  
  149.   DOS_FCB:           ^PC_FCB;
  150.   CPM_FCB:           CpmFCB;
  151.   Buffer:            Bufr;
  152.   DirBuffer:         Bufr;
  153.   DirOffset:         integer;
  154.   DirName:           NameStr;
  155.  {ClusterBuffer:     CBufr;}
  156.   MaxSector:         integer;
  157.   InFile:            File;
  158.   CPMFile:           File;
  159.   BiosError:         boolean;
  160.   VolumeName:        boolean;
  161.   SubDirName:        boolean;
  162.  
  163.   Stop:              boolean;
  164.   Wildcard:          boolean;
  165.   D:                 integer;   {a dummy for function bios3()}
  166.   UnusedBytes:       integer;   {# of unused bytes in the last record}
  167.   MFMTablePointer:   integer;
  168.   BankZeroAddress:   integer;
  169.   DataBuffer:        array[1..DataBufferSize] of char;
  170.   BufferIndex:       integer;
  171.   NumberOfClusters:  integer;
  172.   ExtraBytes:        integer;
  173.  
  174.  
  175. type
  176.   BiosPB = record
  177.     func:     byte;
  178.     aVal:     byte;
  179.     bcVal:    integer;
  180.     deVal:    integer;
  181.     hlVal:    integer;
  182.     end;
  183. var
  184.   Bios_PB: BiosPB;
  185.  
  186.  
  187. function bios3(fn,aReg: byte; bcReg,deReg,hlReg: integer): integer;
  188. begin
  189. if (CPMversion < $30) then
  190.   begin
  191.   case fn of
  192.     9,16,20,22:   bios3 := bioshl(fn-1, bcReg);
  193.     else          bios3 := bios(fn-1, bcReg);
  194.     end;
  195.   end
  196. else
  197.   begin
  198.   with Bios_PB do
  199.     begin
  200.     fillchar(Bios_PB, 8, 0);
  201.     func  := fn;
  202.     aVal  := aReg;
  203.     bcVal := bcReg;
  204.     deVal := deReg;
  205.     hlVal := hlReg;
  206.     case fn of
  207.       9,16,20,22:   bios3 := bdoshl(CALLBIOS, addr(Bios_PB));
  208.       else          bios3 := bdos(CALLBIOS, addr(Bios_PB));
  209.       end;
  210.     end;
  211.   end;
  212. end;
  213.  
  214.  
  215. type
  216.   MFMEntry = record
  217.     classification: byte;
  218.     format:         byte;
  219.     xlt:            integer;
  220.     spt:            integer;
  221.     bsh:            byte;
  222.     blm:            byte;
  223.     exm:            byte;
  224.     dsm:            integer;
  225.     drm:            integer;
  226.     al0:            byte;
  227.     al1:            byte;
  228.     cks:            integer;
  229.     off:            integer;
  230.     psh:            byte;
  231.     phm:            byte;
  232.     pspt:           byte;
  233.     DiskType:       array[1..10] of char;
  234.     end;
  235.  
  236. const
  237.   MS_DOSType: array[0..3] of MFMEntry =
  238.    ((classification:$49; format:$A3; xlt:0; spt:$20; bsh:3; blm:7;
  239.     exm:0; dsm:$13F; drm:$6F; al0:$C0; al1:0; cks:$10;
  240.     off:0; psh:2; phm:3; pspt:8; diskType:'MSDOS-1 DS'),
  241.  
  242.     (classification:$49; format:$A5; xlt:0; spt:$20; bsh:3; blm:7;
  243.     exm:0; dsm:$9F; drm:$3F; al0:$C0; al1:0; cks:$10;
  244.     off:0; psh:2; phm:3; pspt:8; diskType:'MSDOS-1 SS'),
  245.  
  246.     (classification:$4B; format:$A3; xlt:0; spt:$24; bsh:3; blm:7;
  247.     exm:0; dsm:$167; drm:$6F; al0:$C0; al1:0; cks:$10;
  248.     off:0; psh:2; phm:3; pspt:9; diskType:'MSDOS-2 DS'),
  249.  
  250.     (classification:$4B; format:$A5; xlt:0; spt:$24; bsh:3; blm:7;
  251.     exm:0; dsm:$B3; drm:$3F; al0:$C0; al1:0; cks:$10;
  252.     off:0; psh:2; phm:3; pspt:9; diskType:'MSDOS-2 SS'));
  253.  
  254.  
  255. procedure LoadMFMTable(EntryIndex, EntryAddress: integer);
  256. var
  257.   I: integer;
  258. begin
  259. BankZeroAddress := MFMTablePointer + (EntryIndex * 32);
  260. for I := 0 to 31 do
  261.   D := bios3(USERFUN, 1, mem[EntryAddress + I], BankZeroAddress + I, 0);
  262. end;
  263.  
  264.  
  265. procedure CheckWildcard(Filename: Str20);
  266. begin
  267.   Wildcard := false;
  268.   if (pos('*', Filename) > 0) then Wildcard := true;
  269. end;
  270.  
  271.  
  272.  
  273. {$I TRANS-01.INC}
  274. {$I TRANS-02.INC}
  275. {$I TRANS-03.INC}
  276. {$I TRANS-04.INC}
  277. {$I TRANS-05.INC}
  278. {$I TRANS-06.INC}
  279.  
  280.  
  281.  
  282. procedure EraseMS_DOS;        {or rename MS-DOS file}
  283. var
  284.   FileName:          Str20;
  285.   NextCl,I,Err:      integer;
  286.   Cl:                integer;
  287. begin
  288. IdentifyMS_DOS;
  289. if not (Identity = Unidentified) then
  290.   begin
  291.   ClrScr;
  292.   writeln;
  293.  
  294.   if (Selection = '6') then
  295.     write('File Name to Erase From MS-DOS: ')
  296.   else
  297.     write('Old File Name on MS-DOS: ');
  298.  
  299.   readln(FileName);
  300.  
  301.   if (Length(FileName) = 0) then
  302.     exit;
  303.  
  304.   writeln;
  305.   Stop:= false;
  306.  
  307.   CheckWildcard(FileName);
  308.   SearchFirst(FileName,Err);
  309.  
  310.   if (Err = EODirectory) then
  311.     begin
  312.     write('File Not Found, ');
  313.     end
  314.   else
  315.     begin
  316.  
  317.     if (Selection = '8') then
  318.       begin
  319.       if (pos('*', FileName) <> 0) or (pos('?', FileName) <> 0) then
  320.         exit;
  321.       repeat
  322.         Stop := false;
  323.         write('New File Name (<CR> to abort): ');
  324.         readln(FileName);
  325.         if (Length(FileName) = 0) then
  326.           exit;
  327.         for I := 1 to Length(FileName) do
  328.           if not (FileName[I]
  329.                   in ['$', '%', '+', '-'..'9', 'A'..'Z', '_', 'a'..'z']) then
  330.             Stop := true;
  331.         until not Stop;
  332.       ConvertName(FileName, DOS_FCB^.Name, DOS_FCB^.Extention);
  333.       WriteSector(DirSector, DirTrack, addr(DirBuffer));
  334.       if (CPMversion < $30) then
  335.         bdos(RESETDSK);             {to force disk write}
  336.       Continue;
  337.       exit;
  338.       end;
  339.  
  340.     writeln('Erasing -');
  341.  
  342.     repeat
  343.       for I:= 1 to NameSize do
  344.         if not (DOS_FCB^.Name[I] = ' ') then
  345.           write(DOS_FCB^.Name[I]);
  346.       write('.');
  347.       for I:= 1 to TypeSize do
  348.         write(DOS_FCB^.Extention[I]);
  349.       writeln;
  350.  
  351.       Cl:= DOS_FCB^.ClusterNo;
  352.       if (Cl <= NClusters) then
  353.         begin
  354.         NextCl:= Cl;
  355.         repeat
  356.           Cl:= NextCl;
  357.           NextCl:= FATPointer(Cl);
  358.           SetFATPointer(Cl,0);
  359.           until ((NextCl > NClusters) or (NextCl = 0));
  360.         end;
  361.  
  362.       DOS_FCB^.Name[1]:= #$E5;
  363.       WriteSector(DirSector,DirTrack,addr(DirBuffer));
  364.       if Wildcard then
  365.         SearchNext(FileName,Err);
  366.       Stop:= Break;
  367.       until (Err = EODirectory) or Stop or not Wildcard;
  368.  
  369.     PutFAT;
  370.     writeln;
  371.     writeln;
  372.     end;
  373.   if Stop then write('Aborted, ');
  374.   Continue;
  375.   end;
  376. end;
  377.  
  378.  
  379.  
  380.  
  381.  
  382. (********************)
  383. (*                  *)
  384. (*   main program   *)
  385. (*                  *)
  386. (********************)
  387.  
  388.  
  389.  
  390. begin
  391. ClrScr;
  392. CPMversion := bdoshl(GETVSN);
  393. DefaultDisk:= bdos(CURDSK);       {0=A, 1=B...}
  394. CPM_Drive := DefaultDisk;
  395.  
  396. repeat
  397.   gotoxy(1,5);
  398.   write('Which Drive is the MS-DOS Disk in? ');
  399.   read(KBD,Selection);
  400.   write(upcase(Selection),':');
  401.   MS_DOS_Drive:= ord(upcase(Selection)) - ord('A');  {0=A, 1=B...}
  402.   writeln;
  403.   CPM_DriveCh:= chr(CPM_Drive + ord('A'));
  404.   until not ((MS_DOS_Drive < 0) or (MS_DOS_Drive >= 16));
  405.  
  406. writeln;
  407. Delay(500);
  408.  
  409.                                   
  410. MFMTablePointer := mem[$FD46] + mem[$FD46 + 1] *256;
  411. for I := 0 to 3 do                          {load MFM table into bank 0}
  412.   LoadMFMTable(7 + I, addr(MS_DOSType[I]));
  413.  
  414. done:= false;
  415.  
  416. repeat
  417.   Selection:= MainSelection;
  418.   ClrScr;
  419.  
  420.   case Selection of
  421.     '1': WriteMS_DOS;
  422. '0','2': ReadMS_DOS;
  423.     '3': DirMS_DOS;
  424.     '4': MapMS_DOS;
  425.     '5': DirCPM;
  426. '8','6': EraseMS_DOS;
  427.     '7': RestoreFAT;
  428.    {'8': Done := True;}
  429.     '9': FormatMS_DOS;
  430.     #27: Done := true;
  431.     end; (* case *)
  432.  
  433.   until Done;
  434.  
  435.   bdos(RESETDSK);
  436.   bdos(LOGDSK, CPM_Drive);
  437. end.
  438.