1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#include <stdio.h>
#include <stdlib.h> // Just to remove a warning (exit).
#include "args.h"
#include "methods.h"
// Externs.
extern int speed_1,
speed_2,
corr_1,
corr_2;
extern char *filename,
*outfile;
extern void (*method)(byte *);
// Private function prototypes.
int chtoi(char *), // Convert the first char of a string to an integer.
stoi(char *); // Convert a string to an integer.
// Private functions.
// Convert the first char of a string to an integer and check the boundries.
int chtoi(char *string) {
int temp = 0;
if (!string)
return -1;
temp = (int)string[0] - 48;
if ((temp < 0) || (temp > 4))
return -1;
return temp;
}//chtoi
// Convert the a string to an integer and check the boundries.
int stoi(char *string) {
int i = 0,
m = 1,
temp = 0,
ret = 0;
if (!string)
return -100;
if (string[0] == '-') {
m = -1;
i++;
}//if
while (string[i]) {
temp = (int)string[i] - 48;
if ((temp < 0) || (temp > 9))
return -100;
ret *= 10;
ret += temp;
i++;
}//while
if (ret > 50)
return -100;
return m * ret;
}//stoi
// Public functions.
// Print usage and return an error code.
void error(int i) {
printf("Usage: mzf2wav <-i n> <-t n> <-1 n> <-2 n> <-c> <-s> <-w> in out\n"
" -i sets initial speed mode (0, 1, 2, 3 or 4), default = 0.\n"
" -t sets turbo speed mode (0, 1, 2, 3 or 4), default = 2.\n"
" -1 sets correction for fast initial mode (-50 to 50).\n"
" -2 sets correction for fast turbo mode (-50 to 50).\n"
" -c sets conventional writing mode.\n"
" -s sets fast writing mode (default).\n"
" -w sets turbo writing mode.\n"
" -p reverse polarity.\n");
exit(i);
}//error
// Set the configuration variables.
int setvars(int argc, char **argv) {
int temp = 0,
i = 1;
while (i < argc) {
if (argv[i][0] == '-')
switch (argv[i][1]) {
case 'i': // Initial write speed.
temp = chtoi(argv[i + 1]);
if (temp == -1) {
printf("No valid initial speed given.\n");
error(1);
}//if
speed_1 = temp;
i++;
break;
case 't': // Turbo write speed.
temp = chtoi(argv[i + 1]);
if (temp == -1) {
printf("No valid turbo speed given.\n");
error(1);
}//if
speed_2 = temp;
i++;
break;
case '1': // Initial fast correction.
temp = stoi(argv[i + 1]);
if (temp == -100) {
printf("No valid fast initial correction given.\n");
error(1);
}//if
corr_1 = temp;
i++;
break;
case '2': // Initial fast correction.
temp = stoi(argv[i + 1]);
if (temp == -100) {
printf("No valid fast turbo correction given.\n");
error(1);
}//if
corr_2 = temp;
i++;
break;
case 'c':
method = conv;
break;
case 's':
method = trans;
break;
case 'w':
method = turbo;
break;
case 'p':
reversepol();
break;
default:
printf("Unknown option: %s\n", argv[i]);
error(1);
}//switch
else
if (!filename)
filename = argv[i];
else
outfile = argv[i];
i++;
}//while
if (!filename) {
printf("No filename given.\n");
error(1);
}//if
if (!outfile) {
printf("No output filename given.\n");
error(1);
}//if
return 0;
}//setvars
|