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
152
153
154
155
156
157
158
159
160
|
#include "physical.h"
// Defenitions.
#define CONTP 0x37a
extern dword fs;
// Global variables.
byte ZERO = 0x30,
ONE = 0xd0;
int LONG_UP = 0, // These variables define the long wave.
LONG_DOWN = 0,
SHORT_UP = 0, // These variables define the short wave.
SHORT_DOWN = 0,
corr_1 = 0,
corr_2 = 0;
// Private function prototypes.
void lp(void), // Long pulse.
sp(void); // Short pulse.
// Private functions.
// Write a long pulse.
void lp(void) {
int j = 0;
for (j = 0; j < LONG_UP; j++)
outb(ZERO, CONTP);
for (j = 0; j < LONG_DOWN; j++)
outb(ONE, CONTP);
fs += LONG_UP + LONG_DOWN;
}//lp
// Write a short pulse.
void sp(void) {
int j = 0;
for (j = 0; j < SHORT_UP; j++)
outb(ZERO, CONTP);
for (j = 0; j < SHORT_DOWN; j++)
outb(ONE, CONTP);
fs += SHORT_UP + SHORT_DOWN;
}//lp
// Public functions.
// Reverse polarity.
void reversepol(void) {
ZERO = 0xd0;
ONE = 0x30;
}//reversepol
// Write a gap of i short pulses.
void gap(int i) {
int j = 0;
for (j = 0; j < i; j++)
sp();
}//gap
// Write a tapemark of i long pulses, i short pulses and one long pulse.
void tapemark(int i) {
int j = 0;
for (j = 0; j < i; j++)
lp();
for (j = 0; j < i; j++)
sp();
lp();
lp();
}//tapemark
// Write the checksum.
void writecs(word cs) {
byte i = 0x0;
int j = 0;
cs &= 0xffff;
for (j = 0x3; j; j >>= 1) { // for (j = 0; j < 2; j++)
for (i = 0xff; i; i >>= 1) { // for (i = 0; i < 8; i++)
if (cs & 0x8000) // If the most significant bit is set
lp(); // wite a one.
else
sp(); // Else write a zero.
cs <<= 1; // Go to the next bit.
}//for
lp();
}//for
lp();
}//writecs
// Define the waveform to use.
void setspeed(int i) {
switch (i) {
case 1: // Fastest in normal mode. Probably unstable...
LONG_UP = FAST_LONG_UP + corr_1;
LONG_DOWN = FAST_LONG_DOWN + corr_1;
SHORT_UP = FAST_SHORT_UP + corr_1;
SHORT_DOWN = FAST_SHORT_DOWN + corr_1;
break;
case 2: // Turbo mode 2x.
LONG_UP = TURBO_2_LONG_UP;
LONG_DOWN = TURBO_2_LONG_DOWN;
SHORT_UP = TURBO_2_SHORT_UP;
SHORT_DOWN = TURBO_2_SHORT_DOWN;
break;
case 3: // Turbo mode 3x.
LONG_UP = TURBO_3_LONG_UP;
LONG_DOWN = TURBO_3_LONG_DOWN;
SHORT_UP = TURBO_3_SHORT_UP;
SHORT_DOWN = TURBO_3_SHORT_DOWN;
break;
case 4: // Fastest in turbo mode. Probably unstable...
LONG_UP = TURBO_FAST_LONG_UP;
LONG_DOWN = TURBO_FAST_LONG_DOWN + corr_2;
SHORT_UP = TURBO_FAST_SHORT_UP;
SHORT_DOWN = TURBO_FAST_SHORT_DOWN + corr_2;
break;
default: // Normal mode.
LONG_UP = DEFAULT_LONG_UP;
LONG_DOWN = DEFAULT_LONG_DOWN;
SHORT_UP = DEFAULT_SHORT_UP;
SHORT_DOWN = DEFAULT_SHORT_DOWN;
}//switch
}//setspeed
// Write a byte and count the ones for the checksum.
word writebyte(byte b) {
word cs = 0x0;
byte i = 0x0;
for (i = 0xff; i; i >>= 1) {
if (b & 0x80) {
lp();
cs++;
}//if
else
sp();
b <<= 1;
}//for
lp();
return cs;
}//writebyte
// Get the file size.
word getfilesize(byte *image) {
return image[0x12] | (image[0x13] << 8);
}//getfilesize
// See if the MZF file is valid.
int assert(byte *image, word i) {
word fs = getfilesize(image);
if (fs + 0x80 != i) {
if (i - fs > 0x200)
return 2;
if (i < fs)
return 2;
return 1;
}//if
return 0;
}//assert
|