/[projet1]/public/pc/tools/oric/4k8/4k8totap.c
Defence Force logotype

Contents of /public/pc/tools/oric/4k8/4k8totap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 828 - (show annotations)
Thu Apr 26 21:20:08 2012 UTC (7 years, 4 months ago) by mmu_man
File MIME type: text/plain
File size: 1824 byte(s)
Rename to lowercase for consistency.

1 #include <stdio.h>
2
3 int sync_ok=0;
4 int offset;
5 FILE *in, *out;
6
7 main(int argc,char **argv)
8 {
9 unsigned start,end,i;
10 printf(".4k8 -> .tap 1.0\n");
11 if (argc!=3) { printf("Usage: %s file.4k8 file.tap\n",argv[0]); exit(1);}
12 in=fopen(argv[1],"rb"); out=fopen(argv[2],"wb");
13 if (in==NULL || out==NULL) { printf("Unable to open file\n"); exit(1);}
14
15 synchronize();
16 sync_ok=1;
17 while (!feof(in)) putc(getbyte(),out);
18 fclose(in); fclose(out);
19 exit(0);
20 }
21
22
23 getsample()
24 {
25 static int shifter, shiftcount=0;
26 int sample;
27 if (shiftcount==0) {
28 shiftcount=8;
29 if (feof(in)) shifter=0x55;
30 else shifter=getc(in);
31 }
32 shiftcount--;
33 shifter<<=1;
34 return (shifter>>8) & 1;
35 }
36
37 getbit()
38 {
39 int length=0;
40 do length++; while (getsample()==1);
41 do length++; while (getsample()==0);
42 return length<3 ? 1 : 0;
43 }
44
45 getbyte()
46 {
47 int decaleur=0,byte=0,i,bit,sum=0;
48 getbit();
49 while(getbit()==1);
50 for(i=0;i<8;i++) decaleur=(decaleur<<1)|getbit();
51 for(i=0;i<8;i++) {
52 bit=decaleur&1;
53 decaleur=decaleur>>1;
54 byte=(byte<<1)|bit;
55 sum+=bit;
56 }
57 if ((sum&1)==getbit() && sync_ok) printf("parity error at offset $%x\n",offset);
58 return byte;
59 }
60
61 synchronize()
62 {
63 int decaleur=0,val;
64 printf("Searching synchro...\n");
65 while(1) {
66 while((decaleur&0xff) != 0x68)
67 decaleur=(decaleur<<1)|getbit();
68 if (getbyte()!=0x16) continue;
69 if (getbyte()!=0x16) continue;
70 if (getbyte()!=0x16) continue;
71 do {
72 val=getbyte();
73 } while (val==0x16);
74 if (val==0x24) break;
75 }
76 printf("Synchro found, byte coding...\n");
77 putc(0x16,out); putc(0x16,out); putc(0x16,out); putc(0x24,out);
78 }
79

  ViewVC Help
Powered by ViewVC 1.1.26