2 rawrite.c Write a binary image to a 360K diskette.
8 And follow the prompts.
14 1.1 - Beta test (fixing bugs) 4/5/91
15 Some BIOS's don't like full-track writes.
16 1.101 - Last beta release. 4/8/91
17 Fixed BIOS full-track write by only
18 writing 3 sectors at a time.
19 1.2 - Final code and documentation clean-ups. 4/9/91
31 #define SECTORSIZE 512
52 fprintf(stderr
, "%s\n", s
);
56 Identify the error code with a real error message.
58 void Error(int (status
))
61 case 0x00: msg("Operation Successful"); break;
62 case 0x01: msg("Bad command"); break;
63 case 0x02: msg("Address mark not found"); break;
64 case 0x03: msg("Attempt to write on write-protected disk"); break;
65 case 0x04: msg("Sector not found"); break;
66 case 0x05: msg("Reset failed (hard disk)"); break;
67 case 0x06: msg("Disk changed since last operation"); break;
68 case 0x07: msg("Drive parameter activity failed"); break;
69 case 0x08: msg("DMA overrun"); break;
70 case 0x09: msg("Attempt to DMA across 64K boundary"); break;
71 case 0x0A: msg("Bad sector detected"); break;
72 case 0x0B: msg("Bad track detected"); break;
73 case 0x0C: msg("Unsupported track"); break;
74 case 0x10: msg("Bad CRC/ECC on disk read"); break;
75 case 0x11: msg("CRC/ECC corrected data error"); break;
76 case 0x20: msg("Controller has failed"); break;
77 case 0x40: msg("Seek operation failed"); break;
78 case 0x80: msg("Attachment failed to respond"); break;
79 case 0xAA: msg("Drive not ready (hard disk only"); break;
80 case 0xBB: msg("Undefined error occurred (hard disk only)"); break;
81 case 0xCC: msg("Write fault occurred"); break;
82 case 0xE0: msg("Status error"); break;
83 case 0xFF: msg("Sense operation failed"); break;
89 Identify what kind of diskette is installed in the specified drive.
90 Return the number of sectors per track assumed as follows:
91 9 - 360 K and 720 K 5.25".
95 int nsects(int (drive
))
97 static int nsect
[] = {18, 15, 9};
102 Read sector 1, head 0, track 0 to get the BIOS running.
104 buffer
= (char *)malloc(SECTORSIZE
);
105 biosdisk(RESET
, drive
, 0, 0, 0, 0, buffer
);
106 status
= biosdisk(READ
, drive
, 0, 10, 1, 1, buffer
);
107 if (status
== 0x06) /* Door signal change? */
108 status
= biosdisk(READ
, drive
, 0, 0, 1, 1, buffer
);
110 for (i
=0; i
< sizeof(nsect
)/sizeof(int); ++i
) {
111 biosdisk(RESET
, drive
, 0, 0, 0, 0, buffer
);
112 status
= biosdisk(READ
, drive
, 0, 0, nsect
[i
], 1, buffer
);
114 status
= biosdisk(READ
, drive
, 0, 0, nsect
[i
], 1, buffer
);
115 if (status
== 0x00) break;
117 if (i
== sizeof(nsect
)/sizeof(int)) {
118 msg("Can't figure out how many sectors/track for this diskette.");
128 int count
, fdin
, drive
, head
, track
, status
, spt
, buflength
, ns
;
130 puts("RaWrite 1.2 - Write disk file to raw floppy diskette\n");
132 printf("Enter source file name: ");
135 if ((fdin
= open(fname
, O_RDONLY
)) <= 0) {
140 printf("Enter destination drive: ");
142 drive
= (fname
[0] - 'A') & 0xf;
143 printf("Please insert a formatted diskette into ");
144 printf("drive %c: and press -ENTER- :", drive
+ 'A');
145 while (bioskey(1) == 0) ; /* Wait... */
146 if ((bioskey(0) & 0x7F) == 3) exit(1); /* Check for ^C */
150 * Determine number of sectors per track and allocate buffers.
153 buflength
= spt
* SECTORSIZE
;
154 buffer
= (char *)malloc(buflength
);
155 printf("Number of sectors per track for this disk is %d\n", spt
);
156 printf("Writing image to drive %c:. Press ^C to abort.\n", drive
+'A');
158 * Start writing data to diskette until there is no more data to write.
161 while ((count
= read(fdin
, buffer
, buflength
)) > 0 && !done
) {
163 for (ns
= 1; count
> 0 && !done
; ns
+=3) {
164 printf("Track: %02d Head: %2d Sector: %2d\r", track
, head
, ns
);
165 status
= biosdisk(WRITE
, drive
, head
, track
, ns
, 3, pbuf
);
167 if (status
!= 0) Error(status
);
169 count
-= (3*SECTORSIZE
);
170 pbuf
+= (3*SECTORSIZE
);
172 if ((head
= (head
+ 1) & 1) == 0) ++track
;
176 biosdisk(2, drive
, 0, 0, 1, 1, buffer
); /* Retract head */