Bell 32V development
[unix-history] / usr / src / standalone / flpcpy.c
CommitLineData
d52f1552
TL
1# include "CON.h"
2# include "FL.h"
3/* */
4# define BLKSIZ 512 /* tape block size */
5int count , sector , isector , icount ;
6char *bufptr , input[128] , *ibufptr ;
7int wo = 0 ;
8/* */
9main() {
10/*
11* Stand-alone program to copy VAX LSI RX11 floppy diskette to
12* memory and back to floppy.
13* Floppy sector no.'s start at 1 for controller - start at 0
14* for user input.
15* Floppy track no.'s start at 0.
16*/
17register int kk ;
18
19putlin("flpcpy : Floppy-to-Memory-to-Floppy Copy") ;
20putnl() ;
21
22doff :
23putstr("floppy sector offset : ") ;
24getcon(input) ;
25sector = a2l(input) ;
26if ((sector < 0) || (sector >= MAXSEC)) goto doff ;
27
28gknt :
29putstr("no. of input sectors : ") ;
30getcon(input) ;
31count = a2l(input) ;
32if (count < 0) goto gknt ;
33if (count == 0) count = MAXSEC ;
34
35if (init()) {
36 putlin("init error") ;
37 return(-1) ;
38 }
39
40isector = sector ;
41icount = count ;
42
43if (wo) goto wflop ;
44while (count>0) {
45if ((count%100) == 0) {
46 kk = count/100 ;
47 l2a(kk,input) ;
48 putstr(input) ;
49 putstr(" ") ;
50 }
51 if (flio(FL_RS)) { /* read */
52 putlin("floppy input error") ;
53 return(-1) ;
54 }
55 }
56
57putnl() ;
58putlin("floppy read complete") ;
59
60wflop :
61putlin("mount new floppy - type any key when ready") ;
62getcon(input) ;
63
64count = icount ;
65sector = isector ;
66bufptr = ibufptr ;
67
68while (count > 0) {
69if ((count%100) == 0) {
70 kk = count/100 ;
71 l2a(kk,input) ;
72 putstr(input) ;
73 putstr(" ") ;
74 }
75 if (flio(FL_WS)) {
76 putlin("floppy output error") ;
77 return(-1) ;
78 }
79 }
80putnl() ;
81putlin("floppy write complete") ;
82
83end :
84return(0) ;
85}
86
87/* */
88
89init() {
90/*
91* Initialization.
92*/
93extern char *end ;
94
95ibufptr = bufptr = (char *)(((int)&end+511) & 017777777000) ;
96return(0) ;
97}
98
99/* */
100
101flio(func)
102int func ;
103{
104/*
105* Function to read/write 1 sector from floppy disc.
106* 'sector' is sector no.-1 to read into 'input[]'.
107* Return (-1) for error, else return (0) .
108*/
109register int j , s , t ;
110register unsigned int c ;
111
112/* compute start track & sector from current sector 'sector'. */
113t = sector/RXSTRK ; /* track no. */
114s = sector%RXSTRK + 1 ; /* sector */
115sector++ ;
116
117
118fltwait() ;
119mtpr(TXDB,func) ; /* Floppy Read/Write Sector command */
120fltwait() ;
121mtpr(TXDB,s|FL_DATA) ; /* supply sector no. to floppy interface */
122fltwait() ;
123mtpr(TXDB,t|FL_DATA) ; /* track no. */
124
125if (func == FL_RS) { /* Read Sector */
126 /* wait for read to complete */
127 if (fldone()) return(-1) ;
128 /* loop to read sector bytes from interface */
129 for (j = 0 ; j < RXBYSEC ; j++) {
130 flrwait() ; /* wait till ready */
131 (*bufptr++) = mfpr(RXDB) ; /*get data byte-assume from floppy*/
132 }
133 }
134else {
135 if (func == FL_WS) { /* Write Sector */
136 for (j = 0 ; j < RXBYSEC ; j++) {
137 /* send byte over interface */
138 fltwait() ;
139 c = (*bufptr++) & 0xff ;
140 mtpr(TXDB,(c|FL_DATA)) ;
141 }
142 fltwait() ;
143 if (fldone()) return(-1) ;
144 }
145 }
146count-- ;
147return(0) ;
148}