/[projet1]/public/pc/tools/oric/dsk/writedsk.c
Defence Force logotype

Contents of /public/pc/tools/oric/dsk/writedsk.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 837 - (show annotations)
Tue Sep 18 13:21:54 2012 UTC (7 years, 2 months ago) by mmu_man
File MIME type: text/plain
File size: 4074 byte(s)
Rename to lowercase for consistency.

1 /* Watcom compiler */
2 #include <i86.h>
3 #include <bios.h>
4 #include <stdio.h>
5 #define TRACK_SIZE 6400
6 char *version="Writedsk 2.1";
7 unsigned char track[TRACK_SIZE];
8 char pad[256];
9 char chrntab[40][4];
10 int ptr;
11 int drive;
12 int adr;
13 char __far *biosparams;
14 struct diskinfo_t di;
15
16 search_id()
17 {
18 for(;ptr<TRACK_SIZE;ptr++)
19 if ( track[ptr]==0
20 && track[ptr+1]==0
21 && track[ptr+2]==0
22 && track[ptr+3]==0
23 && track[ptr+4]==0xA1
24 && track[ptr+5]==0xA1
25 && track[ptr+6]==0xA1
26 && track[ptr+7]==0xFE) {
27 ptr+=8;
28 return;
29 }
30 }
31
32 find_data()
33 {
34 for(;ptr<TRACK_SIZE;ptr++)
35 if ( track[ptr]==0xA1
36 && track[ptr+1]==0xA1
37 && track[ptr+2]==0xA1
38 && track[ptr+3]==0xFB) {
39 ptr+=4;
40 return;
41 }
42 }
43
44 int write_sector(char *buf,char chrn[4],int track,int head)
45 {
46 struct diskinfo_t di;
47 int try, status;
48
49 biosparams[3]= chrn[3]; /* sector size */
50 for(try=0;try<3;try++) {
51 di.drive=drive;
52 di.head=head;
53 di.track=track;
54 di.sector=chrn[2];
55 di.nsectors=1;
56 di.buffer=(char __far *)buf;
57 status = _bios_disk(_DISK_WRITE,&di) >> 8 ;
58 if (status==0) break;
59 if (status==3) quit("\nWrite protect error\n");
60 }
61 return status;
62 }
63
64 int format_track(char __far *chrnlist,int cyl,int head,int sectors)
65 {
66 int try,status;
67
68 biosparams[7]=40; /* gap */
69 biosparams[4]=sectors;
70 for (try=0;try<3;try++) {
71 di.drive=drive;
72 di.head=head;
73 di.track=cyl;
74 di.sector=1;
75 di.nsectors=sectors;
76 di.buffer=(char __far *)chrnlist;
77 status = _bios_disk(_DISK_FORMAT,&di) >> 8;
78 if (status) _bios_disk(_DISK_RESET,&di);
79 else return 0;
80 }
81 return status;
82 }
83
84 void write_track(int cyl,int head)
85 {
86 int sectors=0, errors, i, try;
87 ptr=0;
88 search_id();
89 while (ptr!=TRACK_SIZE) {
90 chrntab[sectors][0]=track[ptr];
91 chrntab[sectors][1]=track[ptr+1];
92 chrntab[sectors][2]=track[ptr+2];
93 chrntab[sectors][3]=track[ptr+3];
94 find_data();
95 ptr+= 128 << chrntab[sectors][3];
96 sectors++;
97 search_id();
98 }
99 for(try=0;try<3;try++) {
100 ptr=0; errors=0;
101 for(i=0;i<sectors;i++) {
102 search_id();
103 find_data();
104 if (write_sector(track+ptr,chrntab[i],cyl,head)!=0) {
105 errors++;
106 break;
107 }
108 }
109 if (errors==0) { putchar('.'); fflush(stdout); return; }
110 else format_track((char *)chrntab,cyl,head,sectors);
111 }
112 quit("\nWrite error\n");
113 }
114
115
116 init_drive_params()
117 {
118 di.drive=drive;
119 _bios_disk(8,&di); /* bizarre: l'adresse retournee n'est pas 00522, elle pointe sur
120 une table de parametres mais qui n'a pas l'air de servir */
121
122 di.track=79; di.sector=9; di.drive=drive;
123 _bios_disk(0x18,&di);
124
125 biosparams= *(char __far * __far *)MK_FP(0,4*0x1E);
126 biosparams[3]=1;
127 _bios_disk(_DISK_RESET,&di);
128 }
129
130 main(int argc,char *argv[])
131 {
132 FILE *fd;
133 int t,h,tracks,sides,geometry;
134 char diskid[8], *signature="MFM_DISK";
135
136 printf("%s\n",version);
137 if (argc!=3) {
138 printf("Usage: writedsk <disk-image> <floppy-drive:>\n");
139 exit(1);
140 }
141 fd=fopen(argv[1],"rb");
142 if (fd==NULL) {
143 printf("Unable to open %s for reading\n",argv[1]);
144 exit(1);
145 }
146 fread(diskid,8,1,fd);
147 if (strncmp(diskid,signature,8)!=0) {
148 printf("%s is not a disk image\n",argv[1]);
149 exit(1);
150 }
151 if (strcmp(argv[2],"a:")==0 || strcmp(argv[2],"A:")==0)
152 drive=0;
153 else if (strcmp(argv[2],"b:")==0 || strcmp(argv[2],"B:")==0)
154 drive=1;
155 else {
156 printf("Invalid floppy drive specification (%s)\n",argv[2]);
157 exit(1);
158 }
159 fread(&sides,1,2,fd); fread(pad,1,2,fd);
160 fread(&tracks,1,2,fd); fread(pad,1,2,fd);
161 fread(&geometry,1,2,fd); fread(pad,1,2,fd);
162 fread(pad,256-20,1,fd);
163
164 printf("Warning: this operation will erase all data on floppy !\n");
165 printf("Press any key to continue or Ctrl-C to quit\n");
166 getch();
167
168 init_drive_params();
169 for (h=0;h<sides;h++) {
170 for (t=0;t<tracks;t++) {
171 fread(&track,TRACK_SIZE,1,fd);
172 write_track(t,h);
173 }
174 printf("\n");
175 }
176 quit("Write complete\n");
177 }
178
179 quit(char *msg)
180 {
181 printf(msg);
182 biosparams[3]=2; /* restore normal sector size (512) */
183 exit(0);
184 }

  ViewVC Help
Powered by ViewVC 1.1.26