-
Notifications
You must be signed in to change notification settings - Fork 24
/
maketape.c
110 lines (97 loc) · 2.18 KB
/
maketape.c
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
#include <stdio.h>
#define SYNCH 1000
#include <libintl.h>
#include <locale.h>
#define _(String) gettext (String)
#define putSI beep(1, SYNCH), beep(0, SYNCH)
#define put0 beep(1, SYNCH), beep(0, SYNCH), putSI
#define put1 beep(1, 2 * SYNCH), beep(0, 2 * SYNCH), putSI
#define putINM beep(1, 8 * SYNCH)
#define putOUTM beep(1, 4 * SYNCH), beep(0, 4 * SYNCH)
beep(what, len) {
putchar((what << 7) | (len >> 8));
putchar(len & 0xFF);
return 0;
}
putbyte(byte) {
int i;
for (i = 0; i < 8; i++) {
if (byte & 1) put1; else put0;
byte >>= 1;
}
}
putarray(p, l)
unsigned char * p; int l;
{
int i;
for(i = 0; i < l; i++)
putbyte(p[i]);
}
puttune(l) {
while(l--) putSI;
}
#define FAKE_ADDRESS 077777
#define FAKE_LENGTH 1
#define FAKE_CHECKSUM 0177777
void putaddr(FILE * in) {
putbyte(in ? getc(in) : FAKE_ADDRESS & 0xff);
putbyte(in ? getc(in) : FAKE_ADDRESS >> 8);
}
int putlen(FILE * in) {
int len = in ? getc(in) : FAKE_LENGTH & 0xff;
len |= (in ? getc(in) : FAKE_LENGTH >> 8) << 8;
putbyte(len & 0xFF);
putbyte(len >> 8);
return len;
}
main(argc, argv) int argc; char ** argv; {
/* Gettext staff */
setlocale (LC_ALL, "");
bindtextdomain ("bk", "/usr/share/locale");
textdomain ("bk");
int i, sum = 0, len, namelen;
FILE * in;
if (argc != 3) {
fprintf(stderr, _("Usage: maketape BK_NAME infile > outfile\n"));
exit(1);
}
in = fopen(argv[2], "r");
/* If the file cannot be opened, make up a file with
* start address 0, length 0, and a bad tune-up after the header.
*/
putINM;
puttune(010000);
putOUTM;
put1;
puttune(010);
putOUTM;
put1;
/* start address */
putaddr(in);
/* length */
len = putlen(in);
/* name */
namelen = strlen(argv[1]);
putarray(argv[1], namelen > 16 ? 16 : namelen);
if (namelen < 16) putarray("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16 - namelen);
puttune(010);
putOUTM;
put1;
/* data must be here */
while(len--) {
i = in ? getc(in) : 0;
sum += i;
if (sum & 0200000) sum = (sum & 0xFFFF) + 1;
putbyte(i);
}
if (!in) sum = FAKE_CHECKSUM;
/* checksum */
fprintf(stderr, _("checksum = %06o\n"), sum);
putbyte(sum & 0xFF);
putbyte(sum >> 8);
/* exit sequence */
putINM;
puttune(0400);
putOUTM;
put1;
}