/[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 829 - (show annotations)
Thu Apr 26 21:22:08 2012 UTC (7 years, 6 months ago) by mmu_man
File MIME type: text/plain
File size: 1845 byte(s)
Fix warnings.

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

  ViewVC Help
Powered by ViewVC 1.1.26