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