10 * BASE+1 ~ status: BAOSEI??
11 * /BUSY, ACK, PE, SLCT, ERROR, IRQ
12 * BASE+2 ~ control: ??MISIAS
13 * bidirrectMODE, IRQ_EN, /SLCT_IN, INIT, /AUTO_FD_XT, /STROBE
17 * TH, TR, TL, D3, D2, D1, D0
25 * 6 TL <-- 14 /AUTO_FD_XT
28 * 9 TR <-- 17 /SLCT_IN
31 static void inthandler(int u)
33 /* switch TL back to high */
39 int main(int argc, char *argv[])
41 int size, byte, ret, i;
46 if (argc != 4 || argv[1][0] != '-' || (argv[1][1] != 'r' && argv[1][1] != 'w')) {
47 printf("usage:\n%s {-r,-w} <file> <size_hex>\n", argv[0]);
51 file = fopen(argv[2], argv[1][1] == 'r' ? "wb" : "rb");
53 fprintf(stderr, "can't open file: %s\n", argv[2]);
57 size = (int)strtoul(argv[3], &p, 16);
58 if (p == NULL || *p != 0) {
59 fprintf(stderr, "can't convert size %s\n", argv[3]);
65 fprintf(stderr, "can't alloc %d bytes\n", size);
69 ret = ioperm(888, 3, 1);
75 signal(SIGINT, inthandler);
77 printf("regs: %02x %02x %02x\n", inb(888), inb(889), inb(890));
80 while (!(inb(889) & 0x40)) {
81 printf("waiting for TH..\n");
85 if (argv[1][1] == 'r')
87 for (i = 0; i < size; i++)
89 if ((i & 0xff) == 0) {
90 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
91 printf("%06x/%06x", i, size);
95 outb(0xe2, 890); /* TL low */
98 while (inb(889) & 0x40) ;
100 byte = inb(888) & 0x0f;
102 outb(0xe0, 890); /* TL high */
104 /* wait for TH high */
105 while (!(inb(889) & 0x40)) ;
107 byte |= inb(888) << 4;
111 fwrite(data, 1, size, file);
115 ret = fread(data, 1, size, file);
117 printf("warning: read only %d/%d\n", ret, size);
119 outb(0xc0, 890); /* out mode, TL hi */
120 outb(data[0] & 0x0f, 888);
121 outb(0xc2, 890); /* out mode, TL low (start condition) */
123 for (i = 0; i < size; i++)
125 if ((i & 0xff) == 0) {
126 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
127 printf("%06x/%06x", i, size);
131 /* wait for TH low */
132 while (inb(889) & 0x40) ;
136 outb(byte & 0x0f, 888);
137 outb(0xc2, 890); /* TL low */
139 /* wait for TH high */
140 while (!(inb(889) & 0x40)) ;
142 outb(byte >> 4, 888);
143 outb(0xc0, 890); /* TL high */
146 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
147 printf("%06x/%06x\n", i, size);