FreeCalypso > hg > fc-tourmaline
annotate helpers/srec4ram.c @ 89:f4c91ce88c0f
rm src/ui/bmi/mmiFileManager.[ch]
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 08 Nov 2020 01:47:38 +0000 |
parents | 1fb47f5b597a |
children |
rev | line source |
---|---|
9
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This ad hoc utility is used as part of building RAM-loadable |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * firmware images for targets with large RAM. It reads the ramimage.m0 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * S-record file produced by TI's hex470 post-linker and re-emits it |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * in another SREC form that is suitable for feeding to fc-xram. |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/types.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <ctype.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char *infname; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 FILE *inf, *outf; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char srecbuf[80]; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char srecbin[40], srecout[40]; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int lineno; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 decode_hex_byte(s) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char *s; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 register int u, l; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (!isxdigit(s[0]) || !isxdigit(s[1])) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return(-1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (isdigit(s[0])) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 u = s[0] - '0'; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 else if (isupper(s[0])) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 u = s[0] - 'A' + 10; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 else |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 u = s[0] - 'a' + 10; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (isdigit(s[1])) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 l = s[1] - '0'; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 else if (isupper(s[1])) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 l = s[1] - 'A' + 10; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 else |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 l = s[1] - 'a' + 10; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return((u << 4) | l); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 srec2bin() |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 register int i, l, b; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 l = decode_hex_byte(srecbuf + 2); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (l < 1) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fprintf(stderr, "%s line %d: S-record length octet is bad\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 infname, lineno); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 srecbin[0] = l; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (l > 35) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 fprintf(stderr, |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 "%s line %d: S-record is longer than expected\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 infname, lineno); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 for (i = 1; i <= l; i++) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 b = decode_hex_byte(srecbuf + i*2 + 2); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (b < 0) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fprintf(stderr, "%s line %d: hex decode error\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 infname, lineno); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 srecbin[i] = b; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 return(0); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 srec_cksum() |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 u_char accum; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 register int i, len; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 len = srecbin[0] + 1; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 accum = 0; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 for (i = 0; i < len; i++) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 accum += srecbin[i]; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (accum != 0xFF) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fprintf(stderr, "%s line %d: bad checksum\n", infname, lineno); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 return(0); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 emit_output_srec(type, buf) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 u_char *buf; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 int i; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 u_char accum = 0; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 putc('S', outf); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 putc(type, outf); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 for (i = 0; i < buf[0]; i++) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fprintf(outf, "%02X", buf[i]); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 accum += buf[i]; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 fprintf(outf, "%02X\n", ~accum & 0xFF); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 return 0; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 transform_s3() |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 int datalen; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 u_char *sp, *dp; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 int i; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 if (srecbin[0] < 6) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 fprintf(stderr, |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 "%s line %d: S3 record is too short\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 infname, lineno); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 datalen = srecbin[0] - 5; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (datalen & 1) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 fprintf(stderr, "%s line %d: odd data length\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 infname, lineno); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 sp = srecbin; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 dp = srecout; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 for (i = 0; i < 5; i++) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 *dp++ = *sp++; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 for (i = 0; i < datalen; i += 2) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 dp[0] = sp[1]; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 dp[1] = sp[0]; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 sp += 2; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 dp += 2; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 return 0; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 generate_vectors_record() |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 u_char *dp; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 u_long addr; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 int i; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 srecout[0] = 28 + 5; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 srecout[1] = 0x00; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 srecout[2] = 0x80; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 srecout[3] = 0x00; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 srecout[4] = 0x00; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 dp = srecout + 5; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 for (i = 0; i < 7; i++) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 addr = 0x01004000 + i * 4; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 *dp++ = addr; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 *dp++ = addr >> 8; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 *dp++ = addr >> 16; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 *dp++ = addr >> 24; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 emit_output_srec('3', srecout); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 return 0; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 generate_jump_record() |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 srecout[0] = 5; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 srecout[1] = 0x01; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 srecout[2] = 0x00; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 srecout[3] = 0x40; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 srecout[4] = 0x58; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 emit_output_srec('7', srecout); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 return 0; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 main(argc, argv) |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 char **argv; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 if (argc < 2 || argc > 3) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 fprintf(stderr, "usage: %s input.m0 [output.srec]\n", argv[0]); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 infname = argv[1]; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 inf = fopen(infname, "r"); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 if (!inf) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 perror(infname); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 if (argc > 2) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 outf = fopen(argv[2], "w"); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 if (!outf) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 perror(argv[2]); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 } else |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 outf = stdout; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 for (lineno = 1; ; lineno++) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 if (!fgets(srecbuf, sizeof srecbuf, inf)) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 fprintf(stderr, "%s: premature EOF\n", infname); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 if (srecbuf[0] != 'S') { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 fprintf(stderr, "%s line %d: not an S-record\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 infname, lineno); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 srec2bin(); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 srec_cksum(); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 switch (srecbuf[1]) { |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 case '0': |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 emit_output_srec('0', srecbin); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 continue; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 case '3': |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 transform_s3(); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 emit_output_srec('3', srecout); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 continue; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 case '7': |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 break; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 default: |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 fprintf(stderr, "%s line %d: unexpected S%c record\n", |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 infname, lineno, srecbuf[1]); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 exit(1); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 break; |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 } |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 generate_vectors_record(); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 generate_jump_record(); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 exit(0); |
1fb47f5b597a
helpers: import from Magnetite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 } |