1 /* $Id: mccpm.c,v 2.6 1994/06/24 12:58:26 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
7 * dit programma leest een a.out file
8 * voor een kleine uP (adres space = 64K)
9 * en levert aan de standaard output een
10 * download formaat voor de MCCPM computer.
17 char hex[] = "0123456789ABCDEF";
19 int bytes, bytcnt, checksum;
30 fatal ("usage: %s filename [start-adres]\n",argv[0]);
33 if (!(offset = htou(argv[2])))
34 fatal ("adres error %s\n", argv[2]);
35 if (! rd_open(*++argv)) fatal ("can't open %s\n",*argv);
45 struct outsect sect[MAXSECT];
49 if (head.oh_flags & HF_LINK) {
50 fatal("%s contains unresolved references\n",s);
52 rd_sect(sect, head.oh_nsect);
53 for (i = 0; i < head.oh_nsect; i++) {
55 pc = sect[i].os_base - offset;
56 while (sect[i].os_size) {
57 unsigned int sz = 8096, fl;
58 extern char *calloc();
62 if (sz > sect[i].os_size) sz = sect[i].os_size;
63 sect[i].os_size -= sz;
64 pbuf = buf = calloc(sz, 1);
65 if (fl = sect[i].os_flen) {
67 sect[i].os_flen -= fl;
69 rd_emit(buf, (long) fl);
71 while (sz >= MAXBYTE) {
72 data(MAXBYTE, (int) pc, buf);
79 data(sz, (int) pc, buf);
85 printf (":00000001FF\n");
112 checksum = (checksum + b) & 0xFF;
113 putchar (hex[(b>>4) & 0xF]);
114 putchar (hex[b & 0xF]);
120 fprintf (stderr,s,a);
126 fatal("Read error\n");
128 /* convert a string of hex digits to an unsigned 16 bit number */
136 if(c >= '0' && c <= '9')
138 else if(c >= 'a' && c <= 'f')
140 else if(c >= 'A' && c <= 'F')