initial
[fpgammix.git] / workloads / readmoto.c
blob726367195e8681c8cea567810fc49cc7a436f737
1 /*
2 I figured it would be easier to write the assembly if I had a
3 working model in C first ...
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
10 // S11329300FFFFFFFFFFF0F0F0F0F0F0FFFFFFFFF33
12 unsigned sum;
14 void fatal(void)
16 printf("FAILURE\n");
17 exit(1);
20 unsigned getdigit()
22 unsigned c = getchar();
24 if ('0' <= c && c <= '9')
25 return c - '0';
26 else if ('a' <= c && c <= 'f')
27 return c - 'a' + 10;
28 else if ('A' <= c && c <= 'F')
29 return c - 'A' + 10;
30 else
31 fatal();
34 unsigned get2digits()
36 unsigned n = getdigit();
37 n = n*16 + getdigit();
38 sum = 255 & (sum + n);
39 return n;
42 unsigned get4digits()
44 unsigned n = get2digits();
45 return n*256 + get2digits();
49 int
50 main()
52 char buf[999];
54 for (;;) {
55 unsigned type, count, address, i, data, xsum;
56 while (getchar() != 'S');
57 type = getdigit();
58 if (type != 1 && type != 9)
59 continue;
60 sum = 0;
61 count = get2digits();
62 address = get4digits();
63 printf("type %d count %d starting %x\n", type, count, address);
64 for (i = 2; i < count - 1; ++i, ++address) {
65 data = get2digits();
66 printf("%04x:%02x\n", address, data);
68 xsum = get2digits();
69 if (sum != 255)
70 printf("Mismatch %02x =? %02x\n", sum, xsum);