source: thomson/tools/sap/fd2sap.c@ 134f1c4

main
Last change on this file since 134f1c4 was 134f1c4, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Add sapfs (Vital Motion modified code...)

git-svn-id: svn://localhost/thomson@21 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 *
3 * FD2SAP conversion FD => SAP
4 *
5 */
6
7#include <stdio.h>
8#include <strings.h>
9
10
11#define NBSIDE 4
12#define NBTRACK 80
13#define NBSECT 16
14#define SECTSIZE 256
15
16unsigned char disk[NBSIDE][NBTRACK][NBSECT][SECTSIZE];
17
18#define SIDESIZE (NBTRACK*NBSECT*SECTSIZE)
19
20int LoadFD(char * name)
21{
22 FILE * f;
23
24 int sector,track,side;
25 int nb_side,size;
26
27 f=fopen(name,"rb");
28 if (f==NULL) return -1;
29
30 fseek(f, 0L, SEEK_END);
31 size = ftell(f);
32 fseek(f, 0L, SEEK_SET);
33
34 if (size==SIDESIZE) {
35 for (track=0;track<NBTRACK;track++)
36 for (sector=0;sector<NBSECT;sector++)
37 {
38 fread(disk[0][track][sector],sizeof(char),256,f);
39 }
40 return 1;
41 } else
42 if (size==2*SIDESIZE) {
43 for (side=0;side<2;side++)
44 for (track=0;track<NBTRACK;track++)
45 for (sector=0;sector<NBSECT;sector++)
46 {
47 fread(disk[side][track][sector],sizeof(char),256,f);
48 }
49 return 2;
50 }else
51 if (size==4*SIDESIZE) {
52 for (side=0;side<4;side++)
53 for (track=0;track<NBTRACK;track++)
54 for (sector=0;sector<NBSECT;sector++)
55 {
56 fread(disk[side][track][sector],sizeof(char),256,f);
57 }
58 return 4;
59 }
60
61 fclose(f);
62 return 0;
63}
64
65/*
66 ecriture au format TDS
67*/
68void SaveTDS(char * name,int side)
69{
70 FILE * f;
71 char descript[0xA0];
72
73 int i,j;
74
75 /* lecture du descripteur TDS */
76 f=fopen(name,"wb");
77 if (f==NULL) return;
78
79 /* construction du header */
80 for(i=0;i<0xA0;i++)
81 {
82 descript[i]=0;
83 for(j=0;j<8;j++)
84 {
85 if (disk[side][20][1+(i*8)/SECTSIZE][(i*8)%SECTSIZE]!=0xFF)
86 descript[i]|=(1<<j);
87 }
88 }
89 fwrite(descript,sizeof(char),(size_t)0xA0,f);
90
91
92 for (i=0;i<0xA0;i++)
93 for (j=0;j<8;j++)
94 {
95 if ( ( descript[i]&(1<<j) )!=0 )
96 {
97 int SEC,TRK;
98 SEC=(i%2)*8+j;
99 TRK=i/2;
100
101 fwrite(disk[side][TRK][SEC],sizeof(char),(size_t)SECTSIZE,f);
102 }
103 }
104
105 fclose(f);
106}
107
108short crcpuk_temp;
109static const short magic_puk[]={
110
111 0x0000, 0x1081, 0x2102, 0x3183,
112 0x4204, 0x5285, 0x6306, 0x7387,
113 0x8408, 0x9489, 0xa50a, 0xb58b,
114 0xc60c, 0xd68d, 0xe70e, 0xf78f
115
116 };
117
118char * puk_header="\x01SYSTEME D'ARCHIVAGE PUKALL S.A.P. (c) Alexandre PUKALL Avril 1998";
119
120crc_pukall(short c)
121 {
122 register short puk;
123
124 /* on repete le code pour aller plus vite. Pas de boucle ici */
125
126 puk = (crcpuk_temp ^ c) & 0xf;
127 crcpuk_temp = ((crcpuk_temp>>4) & 0xfff) ^ magic_puk[puk];
128
129 c >>= 4;
130
131 puk = (crcpuk_temp ^ c) & 0xf;
132 crcpuk_temp = ((crcpuk_temp>>4) & 0xfff) ^ magic_puk[puk];
133 }
134
135
136void SaveSAP(char * name,int side)
137{
138
139 FILE *f;
140 unsigned char format,protection,piste,secteur;
141
142 char *buffer;
143 int fois;
144 format=0;
145 protection=0; /* variables de test */
146
147 f=fopen(name,"wb");
148 if (f==NULL) return;
149
150/*
151 * Ecriture du header
152 */
153
154 fwrite(puk_header,strlen(puk_header),sizeof(char),f);
155
156/*
157 * Ecriture des donnees
158 */
159
160 for (piste=0;piste<80;piste++)
161 for (secteur=1;secteur<=16;secteur++)
162 {
163
164 crcpuk_temp = 0xffff; /* toujours remettre cette variable a 0xffff */
165 /* pour calculer un nouveau CRC */
166
167 crc_pukall(format); /* calcul du CRC d'un secteur */
168 crc_pukall(protection);
169 crc_pukall(piste);
170 crc_pukall(secteur);
171
172 buffer=disk[side][piste][secteur-1];
173 for (fois=0;fois<=255;fois++) /* on admet que buffer contient les */
174 { /* donnees d'un secteur S.A.P. */
175 crc_pukall(buffer[fois]);
176 buffer[fois]=buffer[fois]^0xb3;
177 }
178
179 fputc(format & 0xFF,f);
180 fputc(protection & 0xFF,f);
181 fputc(piste & 0xFF,f);
182 fputc(secteur & 0xFF,f);
183
184 fwrite(buffer,256,sizeof(char),f);
185
186 fputc((crcpuk_temp >> 8) & 0xFF,f);
187 fputc(crcpuk_temp & 0xFF,f);
188
189
190 }
191
192
193
194 fclose(f);
195}
196
197
198int main(int argc,char * argv[])
199{
200 char str[1024];
201 char str2[1024];
202 char str3[32];
203
204 int i,nb_side;
205
206 if (argc!=3)
207 {
208 fprintf(stderr,"syntaxe : %s <fichier fd source> <fichier SAP dest>\n",argv[0]);
209 exit (-1);
210 }
211
212 nb_side=LoadFD(argv[1]);
213
214 if (nb_side<=0) {
215 fprintf(stderr,"Bad FD file");
216 exit(-1);
217 }
218
219 strcpy(str,argv[2]);
220
221 if (strlen(str)>4)
222 if (strcmp(&str[strlen(str)-4],".sap")==0) str[strlen(str)-4]='\0';
223
224 for (i=0;i<nb_side;i++) {
225 strcpy(str2,str);
226 strcat(str2,"_side");
227 sprintf(str3,"%d",i);
228 strcat(str2,str3);
229 strcat(str2,".sap");
230 SaveSAP(str2,i);
231 }
232}
Note: See TracBrowser for help on using the repository browser.