1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1985-03-18 13:46:31 +00:00
|
|
|
/*
|
|
|
|
* Download Z80 load module into the NASCOM
|
|
|
|
*
|
|
|
|
* Johan Stevenson, Vrije Universiteit, Amsterdam
|
1987-01-29 17:13:37 +00:00
|
|
|
* Adapted (untested) to new ack.out format by
|
1987-01-29 15:54:46 +00:00
|
|
|
* Ceriel Jacobs, Vrije Universiteit, Amsterdam
|
1985-03-18 13:46:31 +00:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sgtty.h>
|
|
|
|
#include <signal.h>
|
1987-01-29 15:54:46 +00:00
|
|
|
#include <out.h>
|
1985-03-18 13:46:31 +00:00
|
|
|
|
|
|
|
int check;
|
|
|
|
int nascom = 1;
|
|
|
|
int nl = '\037';
|
|
|
|
int zero = 0;
|
|
|
|
int disp = 0;
|
|
|
|
|
|
|
|
char hex[] = "0123456789ABCDEF";
|
|
|
|
|
1987-01-29 15:54:46 +00:00
|
|
|
char *progname;
|
|
|
|
|
1985-03-18 13:46:31 +00:00
|
|
|
struct sgttyb ttynormal;
|
|
|
|
struct sgttyb ttyraw;
|
|
|
|
int rawmode = 0;
|
|
|
|
|
1987-01-29 15:54:46 +00:00
|
|
|
struct outhead ohead;
|
|
|
|
struct outsect sect[MAXSECT];
|
|
|
|
|
1985-03-18 13:46:31 +00:00
|
|
|
stop(code) {
|
|
|
|
if (rawmode)
|
|
|
|
stty(1, &ttynormal);
|
|
|
|
exit(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
main(argc,argv) char **argv; {
|
1987-01-29 15:54:46 +00:00
|
|
|
register unsigned nd;
|
|
|
|
long pc;
|
1985-03-18 13:46:31 +00:00
|
|
|
register char *s;
|
1987-01-29 15:54:46 +00:00
|
|
|
int i;
|
1985-03-18 13:46:31 +00:00
|
|
|
|
1987-01-29 15:54:46 +00:00
|
|
|
progname = argv[0];
|
1985-03-18 13:46:31 +00:00
|
|
|
while (argc > 1 && argv[1][0] == '-') {
|
|
|
|
switch (argv[1][1]) {
|
|
|
|
case 'u':
|
|
|
|
/* unix output */
|
|
|
|
nascom = 0;
|
|
|
|
nl = '\n';
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
/* fill EPROM. make minimal change */
|
|
|
|
zero = 0xFF;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
/* displacement at load time */
|
|
|
|
disp = atoi(&argv[1][2]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
s = "a.out";
|
|
|
|
if (argc == 2)
|
|
|
|
s = argv[1];
|
|
|
|
else if (argc != 1) {
|
1987-01-29 17:13:37 +00:00
|
|
|
fprintf(stderr,"usage: %s [flags] [object file]\n",progname);
|
1985-03-18 13:46:31 +00:00
|
|
|
stop(-1);
|
|
|
|
}
|
1987-01-29 15:54:46 +00:00
|
|
|
if (! rd_open(s)) {
|
1987-01-29 17:13:37 +00:00
|
|
|
fprintf(stderr,"%s: can't open %s\n",progname,s);
|
1985-03-18 13:46:31 +00:00
|
|
|
stop(-1);
|
|
|
|
}
|
|
|
|
if (nascom) {
|
|
|
|
signal(SIGHUP, SIG_IGN);
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
signal(SIGQUIT, stop);
|
|
|
|
signal(SIGTERM, stop);
|
|
|
|
if (gtty(1, &ttynormal) < 0) {
|
|
|
|
fprintf(stderr, "no tty\n");
|
|
|
|
stop(-1);
|
|
|
|
}
|
|
|
|
rawmode++;
|
|
|
|
ttyraw = ttynormal;
|
|
|
|
ttyraw.sg_flags |= RAW;
|
|
|
|
ttyraw.sg_ispeed = B1200;
|
|
|
|
ttyraw.sg_ospeed = B1200;
|
|
|
|
stty(1, &ttyraw);
|
|
|
|
sleep(5);
|
|
|
|
}
|
1987-01-29 15:54:46 +00:00
|
|
|
rd_ohead(&ohead);
|
1987-01-29 17:13:37 +00:00
|
|
|
if (ohead.oh_flags & HF_LINK) {
|
|
|
|
fprintf(stderr,"%s: %s contains unresolved references\n",progname,s);
|
|
|
|
stop(-1);
|
|
|
|
}
|
1987-01-29 15:54:46 +00:00
|
|
|
rd_sect(sect, ohead.oh_nsect);
|
|
|
|
for (i = 0; i < ohead.oh_nsect; i++) {
|
|
|
|
rd_outsect(i);
|
|
|
|
pc = sect[i].os_base;
|
|
|
|
while (sect[i].os_size) {
|
|
|
|
unsigned int sz = 8096, fl;
|
|
|
|
extern char *calloc();
|
|
|
|
register char *buf;
|
|
|
|
char *pbuf;
|
|
|
|
|
|
|
|
if (sz > sect[i].os_size) sz = sect[i].os_size;
|
|
|
|
sect[i].os_size -= sz;
|
|
|
|
pbuf = buf = calloc(sz, 1);
|
|
|
|
if (fl = sect[i].os_flen) {
|
|
|
|
if (fl > sz) fl = sz;
|
|
|
|
sect[i].os_flen -= fl;
|
|
|
|
|
|
|
|
rd_emit(buf, (long) fl);
|
|
|
|
}
|
|
|
|
while (sz >= 8) {
|
|
|
|
data(8, (int) pc, buf);
|
|
|
|
sz -= 8;
|
|
|
|
buf += 8;
|
|
|
|
pc += 8;
|
|
|
|
}
|
|
|
|
if (sz > 0) {
|
|
|
|
data(sz, (int) pc, buf);
|
|
|
|
}
|
|
|
|
free(pbuf);
|
1985-03-18 13:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
putchar('.');
|
|
|
|
putchar(nl);
|
|
|
|
if (nascom)
|
|
|
|
sleep(5);
|
|
|
|
stop(0);
|
|
|
|
}
|
|
|
|
|
1987-01-29 15:54:46 +00:00
|
|
|
data(nd,pc,buf)
|
|
|
|
register char *buf;
|
|
|
|
int pc;
|
|
|
|
{
|
1985-03-18 13:46:31 +00:00
|
|
|
register i;
|
|
|
|
|
|
|
|
check = 0;
|
|
|
|
pc += disp;
|
|
|
|
byte(pc>>8);
|
|
|
|
byte(pc);
|
|
|
|
for (i = 0; i < nd; i++) {
|
|
|
|
putchar(' ');
|
1987-01-29 15:54:46 +00:00
|
|
|
byte(*buf++);
|
1985-03-18 13:46:31 +00:00
|
|
|
}
|
|
|
|
while (i < 8) {
|
|
|
|
putchar(' ');
|
|
|
|
byte(zero);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
putchar(' ');
|
|
|
|
byte(check);
|
|
|
|
putchar(nl);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte(b) {
|
|
|
|
|
|
|
|
check += b;
|
|
|
|
putchar(hex[(b>>4) & 017]);
|
|
|
|
putchar(hex[b & 017]);
|
|
|
|
}
|
|
|
|
|
1987-01-29 15:54:46 +00:00
|
|
|
rd_fatal()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: Read error\n", progname);
|
|
|
|
stop(-1);
|
1985-03-18 13:46:31 +00:00
|
|
|
}
|