1*1016Sbill static char *sccsid = "@(#)flcopy.c 4.1 (Berkeley) 10/01/80"; 2*1016Sbill int floppydes; 3*1016Sbill char *flopname = "/dev/floppy"; 4*1016Sbill 5*1016Sbill main(argc,argv) 6*1016Sbill char *argv[]; 7*1016Sbill { 8*1016Sbill static char buff[512]; 9*1016Sbill register count = 77 * 26 * 128, startad = -26 * 128; 10*1016Sbill register int n, file; 11*1016Sbill 12*1016Sbill if(argc==2) { 13*1016Sbill printf("Halftime!\n"); 14*1016Sbill if(strcmp(argv[1],"-h")!=0) 15*1016Sbill printf("Bad halftime option.\n"), 16*1016Sbill exit(1); 17*1016Sbill if((file = open("floppy",0))<0) 18*1016Sbill printf("failed to open floppy image"), 19*1016Sbill exit(1); 20*1016Sbill goto halftime; 21*1016Sbill } 22*1016Sbill file = creat("floppy",0666); 23*1016Sbill close(file); 24*1016Sbill file = open("floppy",2); 25*1016Sbill if(file < 0) exit(1); 26*1016Sbill for( ; count > 0 ; count -= 512) { 27*1016Sbill n = count > 512 ? 512 : count ; 28*1016Sbill lread(startad,n,buff); 29*1016Sbill write(file,buff,n); 30*1016Sbill startad += 512; 31*1016Sbill } 32*1016Sbill halftime: 33*1016Sbill printf("Change Floppy, Hit return when done.\n"); 34*1016Sbill gets(buff); 35*1016Sbill lseek(file,0,0); 36*1016Sbill count = 77 * 26 * 128; startad = -26 * 128; 37*1016Sbill for( ; count > 0 ; count -= 512) { 38*1016Sbill n = count > 512 ? 512 : count ; 39*1016Sbill read(file,buff,n); 40*1016Sbill lwrite(startad,n,buff); 41*1016Sbill startad += 512; 42*1016Sbill } 43*1016Sbill } 44*1016Sbill rt_init() 45*1016Sbill { 46*1016Sbill static initized = 0; 47*1016Sbill int mode = 2; 48*1016Sbill 49*1016Sbill if(initized) return; 50*1016Sbill initized = 1; 51*1016Sbill if((floppydes = open(flopname,mode)) < 0) { 52*1016Sbill printf("Floppy open failed\n"); 53*1016Sbill exit(1); 54*1016Sbill } 55*1016Sbill } 56*1016Sbill 57*1016Sbill long trans(logical) 58*1016Sbill register int logical; 59*1016Sbill { 60*1016Sbill /* Logical to physical adress translation */ 61*1016Sbill register int sector, bytes, track; 62*1016Sbill 63*1016Sbill logical += 26 * 128; 64*1016Sbill bytes = (logical & 127); 65*1016Sbill logical >>= 7; 66*1016Sbill sector = logical % 26; 67*1016Sbill if(sector >= 13) 68*1016Sbill sector = sector *2 +1; 69*1016Sbill else 70*1016Sbill sector *= 2; 71*1016Sbill sector += 26 + ((track = (logical / 26)) - 1) * 6; 72*1016Sbill sector %= 26; 73*1016Sbill return( (((track *26) + sector) << 7) + bytes); 74*1016Sbill } 75*1016Sbill lread(startad,count,obuff) 76*1016Sbill register startad, count; 77*1016Sbill register char * obuff; 78*1016Sbill { 79*1016Sbill long trans(); 80*1016Sbill extern floppydes; 81*1016Sbill rt_init(); 82*1016Sbill while( (count -= 128) >= 0) { 83*1016Sbill lseek(floppydes, trans(startad), 0); 84*1016Sbill read(floppydes,obuff,128); 85*1016Sbill obuff += 128; 86*1016Sbill startad += 128; 87*1016Sbill } 88*1016Sbill } 89*1016Sbill lwrite(startad,count,obuff) 90*1016Sbill register startad, count; 91*1016Sbill register char * obuff; 92*1016Sbill { 93*1016Sbill long trans(); 94*1016Sbill extern floppydes; 95*1016Sbill rt_init(); 96*1016Sbill while( (count -= 128) >= 0) { 97*1016Sbill lseek(floppydes, trans(startad), 0); 98*1016Sbill write(floppydes,obuff,128); 99*1016Sbill obuff += 128; 100*1016Sbill startad += 128; 101*1016Sbill } 102*1016Sbill } 103