mirror of
https://github.com/fachat/xa65.git
synced 2024-06-17 20:29:32 +00:00
formatted source according to K&R
This commit is contained in:
parent
3be092964c
commit
b5cda1bd88
112
xa/misc/file65.c
112
xa/misc/file65.c
|
@ -1,7 +1,7 @@
|
|||
/* file65 -- A part of xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
* Print information about o65 files
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -111,7 +111,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
i = 1;
|
||||
|
||||
if (strstr(argv[i], "--help") || strstr(argv[i], "-?") || strstr(argv[i], "-h")) {
|
||||
if (strstr(argv[i], "--help") || strstr(argv[i], "-?")
|
||||
|| strstr(argv[i], "-h")) {
|
||||
usage(stdout);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -135,16 +136,21 @@ int main(int argc, char *argv[]) {
|
|||
case 'a':
|
||||
case 'A':
|
||||
rompar = 1;
|
||||
if(argv[i][1]=='A') rompar++;
|
||||
if(argv[i][2]) romoff = atoi(argv[i]+2);
|
||||
else if(i + 1 < argc) romoff = atoi(argv[++i]);
|
||||
else fprintf(stderr,"%s: missing offset\n",programname);
|
||||
if (argv[i][1] == 'A')
|
||||
rompar++;
|
||||
if (argv[i][2])
|
||||
romoff = atoi(argv[i] + 2);
|
||||
else if (i + 1 < argc)
|
||||
romoff = atoi(argv[++i]);
|
||||
else
|
||||
fprintf(stderr, "%s: missing offset\n", programname);
|
||||
break;
|
||||
case 'P':
|
||||
xapar = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"%s: %s unknown option, use '-h' for help\n",programname,argv[i]);
|
||||
fprintf(stderr, "%s: %s unknown option, use '-h' for help\n",
|
||||
programname, argv[i]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -157,7 +163,8 @@ int main(int argc, char *argv[]) {
|
|||
printf("%s: o65 version %d %s file\n", argv[i], hdr[5],
|
||||
hdr[7] & 0x10 ? "object" : "executable");
|
||||
printf(" mode: %04x =", mode);
|
||||
printf("[%s][%sbit][%s relocation][CPU %s][CPU2 %s]%s\n",
|
||||
printf(
|
||||
"[%s][%sbit][%s relocation][CPU %s][CPU2 %s]%s\n",
|
||||
(mode & 0x1000) ? "object" : "executable",
|
||||
(mode & 0x2000) ? "32" : "16",
|
||||
(mode & 0x4000) ? "page" : "byte",
|
||||
|
@ -166,31 +173,40 @@ int main(int argc, char *argv[]) {
|
|||
aligntxt[mode & 3]);
|
||||
}
|
||||
if (mode & 0x2000) {
|
||||
fprintf(stderr,"file65: %s: 32 bit size not supported\n", argv[i]);
|
||||
fprintf(stderr,
|
||||
"file65: %s: 32 bit size not supported\n",
|
||||
argv[i]);
|
||||
} else {
|
||||
n = fread(hdr + 8, 1, 18, fp);
|
||||
if (n < 18) {
|
||||
fprintf(stderr,"file65: %s: truncated file\n", argv[i]);
|
||||
fprintf(stderr, "file65: %s: truncated file\n",
|
||||
argv[i]);
|
||||
} else {
|
||||
if (!xapar && !rompar) {
|
||||
printf(" text segment @ $%04x - $%04x [$%04x bytes]\n", hdr[9]*256+hdr[8], hdr[9]*256+hdr[8]+hdr[11]*256+hdr[10], hdr[11]*256+hdr[10]);
|
||||
printf(" data segment @ $%04x - $%04x [$%04x bytes]\n", hdr[13]*256+hdr[12], hdr[13]*256+hdr[12]+hdr[15]*256+hdr[14], hdr[15]*256+hdr[14]);
|
||||
printf(" bss segment @ $%04x - $%04x [$%04x bytes]\n", hdr[17]*256+hdr[16], hdr[17]*256+hdr[16]+hdr[19]*256+hdr[18], hdr[19]*256+hdr[18]);
|
||||
printf(" zero segment @ $%04x - $%04x [$%04x bytes]\n", hdr[21]*256+hdr[20], hdr[21]*256+hdr[20]+hdr[23]*256+hdr[22], hdr[23]*256+hdr[22]);
|
||||
printf(" stack size $%04x bytes %s\n", hdr[25]*256+hdr[24],
|
||||
(hdr[25]*256+hdr[24])==0?"(i.e. unknown)":"");
|
||||
printf(" text segment @ $%04x - $%04x [$%04x bytes]\n",
|
||||
hdr[9]*256+hdr[8], hdr[9]*256+hdr[8]+hdr[11]*256+hdr[10], hdr[11]*256+hdr[10]);
|
||||
printf(" data segment @ $%04x - $%04x [$%04x bytes]\n",
|
||||
hdr[13]*256+hdr[12], hdr[13]*256+hdr[12]+hdr[15]*256+hdr[14], hdr[15]*256+hdr[14]);
|
||||
printf(" bss segment @ $%04x - $%04x [$%04x bytes]\n",
|
||||
hdr[17]*256+hdr[16], hdr[17]*256+hdr[16]+hdr[19]*256+hdr[18], hdr[19]*256+hdr[18]);
|
||||
printf(" zero segment @ $%04x - $%04x [$%04x bytes]\n",
|
||||
hdr[21]*256+hdr[20], hdr[21]*256+hdr[20]+hdr[23]*256+hdr[22], hdr[23]*256+hdr[22]);
|
||||
printf(" stack size $%04x bytes %s\n",
|
||||
hdr[25]*256+hdr[24], (hdr[25]*256+hdr[24])==0?"(i.e. unknown)":"");
|
||||
if (verbose) {
|
||||
read_options(fp);
|
||||
print_labels(fp, hdr[11]*256+hdr[10] + hdr[15]*256+hdr[14]);
|
||||
print_labels(fp,
|
||||
hdr[11] * 256 + hdr[10]
|
||||
+ hdr[15] * 256 + hdr[14]);
|
||||
}
|
||||
} else {
|
||||
struct stat fbuf;
|
||||
hlen = 8 + 18 + read_options(fp);
|
||||
stat(argv[i], &fbuf);
|
||||
if (xapar) {
|
||||
if(!rompar) printf("-bt %d ",
|
||||
(hdr[9]*256+hdr[8]) + (hdr[11]*256+hdr[10])
|
||||
);
|
||||
if (!rompar)
|
||||
printf("-bt %d ",
|
||||
(hdr[9]*256+hdr[8])+(hdr[11]*256+hdr[10]));
|
||||
printf("-bd %d -bb %d -bz %d ",
|
||||
(hdr[13]*256+hdr[12]) + (hdr[15]*256+hdr[14]),
|
||||
(hdr[17]*256+hdr[16]) + (hdr[19]*256+hdr[18]),
|
||||
|
@ -198,12 +214,15 @@ int main(int argc, char *argv[]) {
|
|||
);
|
||||
}
|
||||
if (rompar == 1) {
|
||||
printf("-A %lu ", (unsigned long)((hdr[9]*256+hdr[8])
|
||||
-hlen +romoff +(fbuf.st_size)));
|
||||
} else
|
||||
if(rompar==2) {
|
||||
printf("%lu ", (unsigned long)((hdr[9]*256+hdr[8])
|
||||
-hlen +romoff +(fbuf.st_size)));
|
||||
printf("-A %lu ",
|
||||
(unsigned long) ((hdr[9] * 256
|
||||
+ hdr[8]) - hlen + romoff
|
||||
+ (fbuf.st_size)));
|
||||
} else if (rompar == 2) {
|
||||
printf("%lu ",
|
||||
(unsigned long) ((hdr[9] * 256
|
||||
+ hdr[8]) - hlen + romoff
|
||||
+ (fbuf.st_size)));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -212,10 +231,13 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
fprintf(stderr, "file65: %s: not an o65 file!\n", argv[i]);
|
||||
if (hdr[0] == 1 && hdr[1] == 8 && hdr[3] == 8) {
|
||||
printf("%s: C64 BASIC executable (start address $0801)?\n", argv[i]);
|
||||
} else
|
||||
if(hdr[0]==1 && hdr[1]==4 && hdr[3]==4) {
|
||||
printf("%s: CBM PET BASIC executable (start address $0401)?\n", argv[i]);
|
||||
printf(
|
||||
"%s: C64 BASIC executable (start address $0801)?\n",
|
||||
argv[i]);
|
||||
} else if (hdr[0] == 1 && hdr[1] == 4 && hdr[3] == 4) {
|
||||
printf(
|
||||
"%s: CBM PET BASIC executable (start address $0401)?\n",
|
||||
argv[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -249,7 +271,9 @@ static char* stab[] = {
|
|||
|
||||
void print_option(unsigned char *buf, int len) {
|
||||
int i, strfl = 0;
|
||||
for(i=0;otab[i].opt>=0; i++) if(*buf==otab[i].opt) break;
|
||||
for (i = 0; otab[i].opt >= 0; i++)
|
||||
if (*buf == otab[i].opt)
|
||||
break;
|
||||
if (otab[i].opt >= 0) {
|
||||
printf("fopt: %-17s: ", otab[i].string);
|
||||
strfl = otab[i].strfl;
|
||||
|
@ -271,11 +295,13 @@ int read_options(FILE *fp) {
|
|||
int c, d, l = 0;
|
||||
unsigned char tb[256];
|
||||
|
||||
c=fgetc(fp); l++;
|
||||
c = fgetc(fp);
|
||||
l++;
|
||||
while (c && c != EOF) {
|
||||
c &= 255;
|
||||
d = fread(tb, 1, c - 1, fp);
|
||||
if(labels) print_option(tb, c);
|
||||
if (labels)
|
||||
print_option(tb, c);
|
||||
l += c;
|
||||
c = fgetc(fp);
|
||||
}
|
||||
|
@ -284,8 +310,10 @@ int read_options(FILE *fp) {
|
|||
|
||||
int print_labels(FILE *fp, int offset) {
|
||||
int i, nud, c, seg, off;
|
||||
const char *segments[] = { "undef", "abs", "text", "data", "bss", "zero" };
|
||||
const char *reltype[] = { "-", "LOW", "HIGH", "-", "WORD", "SEG", "SEGADDR" };
|
||||
const char *segments[] =
|
||||
{ "undef", "abs", "text", "data", "bss", "zero" };
|
||||
const char *reltype[] =
|
||||
{ "-", "LOW", "HIGH", "-", "WORD", "SEG", "SEGADDR" };
|
||||
|
||||
/*
|
||||
printf("print_labels:offset=%d\n",offset);
|
||||
|
@ -331,10 +359,12 @@ printf("print_labels:offset=%d\n",offset);
|
|||
while (c == 255 && c != EOF) {
|
||||
offset += 254;
|
||||
c = fgetc(fp);
|
||||
if(c==EOF) break;
|
||||
if (c == EOF)
|
||||
break;
|
||||
c &= 0xff;
|
||||
}
|
||||
if(c==EOF) break;
|
||||
if (c == EOF)
|
||||
break;
|
||||
offset += c;
|
||||
|
||||
c = fgetc(fp);
|
||||
|
@ -346,7 +376,8 @@ printf("print_labels:offset=%d\n",offset);
|
|||
index += (fgetc(fp) & 0xff) << 8;
|
||||
}
|
||||
if (verbose > 1) {
|
||||
printf("\t%d:%s(%s (%d)", offset, reltype[ (c>>5) & 0xf], segments[c & 0x07], (c&0x07));
|
||||
printf("\t%d:%s(%s (%d)", offset, reltype[(c >> 5) & 0xf],
|
||||
segments[c & 0x07], (c & 0x07));
|
||||
if ((c & 0xe0) == 0x40) {
|
||||
printf(", %02x", lowbyte);
|
||||
}
|
||||
|
@ -362,7 +393,6 @@ printf("print_labels:offset=%d\n",offset);
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// print global labels
|
||||
nud = (fgetc(fp) & 0xff);
|
||||
|
@ -376,7 +406,8 @@ printf("print_labels:offset=%d\n",offset);
|
|||
fputc(c, stdout);
|
||||
c = fgetc(fp);
|
||||
}
|
||||
if(c==EOF) break;
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
seg = fgetc(fp) & 0xff;
|
||||
off = (fgetc(fp) & 0xff);
|
||||
|
@ -388,4 +419,3 @@ printf("print_labels:offset=%d\n",offset);
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
249
xa/misc/ldo65.c
249
xa/misc/ldo65.c
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* A part of the xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1997-2023 André Fachat (fachat@web.de)
|
||||
* Copyright (C) 1997-2023 Andr<EFBFBD> Fachat (fachat@web.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -69,7 +69,6 @@ The process of linking works as follows:
|
|||
#define FM_CPU2_NMOS 0x0040
|
||||
#define FM_CPU2_65816E 0x0050
|
||||
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int len;
|
||||
|
@ -127,7 +126,6 @@ typedef struct {
|
|||
file65 *file; /* in which file is it? */
|
||||
} glob;
|
||||
|
||||
|
||||
file65* load_file(char *fname);
|
||||
|
||||
int read_options(unsigned char *f);
|
||||
|
@ -135,7 +133,8 @@ int read_undef(unsigned char *f, file65 *fp);
|
|||
int write_undef(FILE *f, file65 *fp);
|
||||
int check_undef(file65 *fp, char *defined[], int ndefined);
|
||||
int len_reloc_seg(unsigned char *buf, int ri);
|
||||
int reloc_seg(unsigned char *buf, int pos, int addr, int rdiff, int ri, unsigned char *obuf, int *lastaddrp, int *rop, file65 *fp);
|
||||
int reloc_seg(unsigned char *buf, int pos, int addr, int rdiff, int ri,
|
||||
unsigned char *obuf, int *lastaddrp, int *rop, file65 *fp);
|
||||
unsigned char* reloc_globals(unsigned char*, file65 *fp);
|
||||
int read_globals(file65 *file);
|
||||
int write_options(FILE *fp, file65 *file);
|
||||
|
@ -220,7 +219,8 @@ int main(int argc, char *argv[]) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (strstr(argv[1], "--help") || strstr(argv[1], "-?") || strstr(argv[1], "-h")) {
|
||||
if (strstr(argv[1], "--help") || strstr(argv[1], "-?")
|
||||
|| strstr(argv[1], "-h")) {
|
||||
usage(stdout);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -249,31 +249,35 @@ int main(int argc, char *argv[]) {
|
|||
undefok = 1;
|
||||
break;
|
||||
case 'o':
|
||||
if(argv[i][2]) outfile=argv[i]+2;
|
||||
else outfile=argv[++i];
|
||||
if (argv[i][2])
|
||||
outfile = argv[i] + 2;
|
||||
else
|
||||
outfile = argv[++i];
|
||||
break;
|
||||
case 'g':
|
||||
noglob = 1;
|
||||
if(argv[i][2]) arg=argv[i]+2;
|
||||
else arg=argv[++i];
|
||||
if (argv[i][2])
|
||||
arg = argv[i] + 2;
|
||||
else
|
||||
arg = argv[++i];
|
||||
if (ngloballoc == 0) {
|
||||
ngloballoc = 20;
|
||||
globdef = malloc(ngloballoc * sizeof(char*));
|
||||
} else
|
||||
if (nglobal >= ngloballoc) {
|
||||
} else if (nglobal >= ngloballoc) {
|
||||
ngloballoc *= 2;
|
||||
globdef = realloc(globdef, ngloballoc * sizeof(char*));
|
||||
}
|
||||
globdef[nglobal++] = arg;
|
||||
break;
|
||||
case 'L':
|
||||
if(argv[i][2]) arg=argv[i]+2;
|
||||
else arg=argv[++i];
|
||||
if (argv[i][2])
|
||||
arg = argv[i] + 2;
|
||||
else
|
||||
arg = argv[++i];
|
||||
if (ndefalloc == 0) {
|
||||
ndefalloc = 20;
|
||||
defined = malloc(ndefalloc * sizeof(char*));
|
||||
} else
|
||||
if (ndefined >= ndefalloc) {
|
||||
} else if (ndefined >= ndefalloc) {
|
||||
ndefalloc *= 2;
|
||||
defined = realloc(defined, ndefalloc * sizeof(char*));
|
||||
}
|
||||
|
@ -282,20 +286,28 @@ int main(int argc, char *argv[]) {
|
|||
case 'b':
|
||||
switch (argv[i][2]) {
|
||||
case 't':
|
||||
if(argv[i][3]) tbase = atoi(argv[i]+3);
|
||||
else tbase = atoi(argv[++i]);
|
||||
if (argv[i][3])
|
||||
tbase = atoi(argv[i] + 3);
|
||||
else
|
||||
tbase = atoi(argv[++i]);
|
||||
break;
|
||||
case 'd':
|
||||
if(argv[i][3]) dbase = atoi(argv[i]+3);
|
||||
else dbase = atoi(argv[++i]);
|
||||
if (argv[i][3])
|
||||
dbase = atoi(argv[i] + 3);
|
||||
else
|
||||
dbase = atoi(argv[++i]);
|
||||
break;
|
||||
case 'b':
|
||||
if(argv[i][3]) bbase = atoi(argv[i]+3);
|
||||
else bbase = atoi(argv[++i]);
|
||||
if (argv[i][3])
|
||||
bbase = atoi(argv[i] + 3);
|
||||
else
|
||||
bbase = atoi(argv[++i]);
|
||||
break;
|
||||
case 'z':
|
||||
if(argv[i][3]) zbase = atoi(argv[i]+3);
|
||||
else zbase = atoi(argv[++i]);
|
||||
if (argv[i][3])
|
||||
zbase = atoi(argv[i] + 3);
|
||||
else
|
||||
zbase = atoi(argv[++i]);
|
||||
break;
|
||||
default:
|
||||
printf("Unknown segment type '%c' - ignored!\n", argv[i][2]);
|
||||
|
@ -303,7 +315,8 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"file65: %s unknown option, use '-h for help\n",argv[i]);
|
||||
fprintf(stderr, "file65: %s unknown option, use '-h for help\n",
|
||||
argv[i]);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
|
@ -313,13 +326,19 @@ int main(int argc, char *argv[]) {
|
|||
// step 1 - load files
|
||||
|
||||
/* each file is loaded first */
|
||||
j=0; jm=0; fp=NULL;
|
||||
j = 0;
|
||||
jm = 0;
|
||||
fp = NULL;
|
||||
while (i < argc) {
|
||||
file65 *f;
|
||||
f = load_file(argv[i]);
|
||||
if (f) {
|
||||
if(j>=jm) fp=realloc(fp, (jm=(jm?jm*2:10))*sizeof(file65*));
|
||||
if(!fp) { fprintf(stderr,"Oops, no more memory\n"); exit(1); }
|
||||
if (j >= jm)
|
||||
fp = realloc(fp, (jm = (jm ? jm * 2 : 10)) * sizeof(file65*));
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Oops, no more memory\n");
|
||||
exit(1);
|
||||
}
|
||||
fp[j++] = f;
|
||||
} else {
|
||||
exit(1);
|
||||
|
@ -352,7 +371,8 @@ int main(int argc, char *argv[]) {
|
|||
// 65816
|
||||
trgmode |= 0x8000;
|
||||
if (trgcpu == 4) {
|
||||
fprintf(stderr, "Error: file '%s' in 65816 CPU mode is incompatible with previous NMOS undocumented opcodes CPU mode\n",
|
||||
fprintf(stderr,
|
||||
"Error: file '%s' in 65816 CPU mode is incompatible with previous NMOS undocumented opcodes CPU mode\n",
|
||||
file->fname);
|
||||
er = 1;
|
||||
}
|
||||
|
@ -364,8 +384,10 @@ int main(int argc, char *argv[]) {
|
|||
// CPU bits
|
||||
fcpu = (file->mode & FM_CPU2) >> 4;
|
||||
if (verbose) {
|
||||
printf("Matching file %s with CPU %s (%d) to target %s (%d) ...\n",
|
||||
file->fname, cpunames[fcpu], fcpu, cpunames[trgcpu], trgcpu);
|
||||
printf(
|
||||
"Matching file %s with CPU %s (%d) to target %s (%d) ...\n",
|
||||
file->fname, cpunames[fcpu], fcpu, cpunames[trgcpu],
|
||||
trgcpu);
|
||||
}
|
||||
switch (fcpu) {
|
||||
case 0x0: // bare minimum documented 6502 is just fine
|
||||
|
@ -383,9 +405,11 @@ int main(int argc, char *argv[]) {
|
|||
case 0x2: // 65SC02 - CMOS without BBR/BBS/RMB/SMB, compatible with 65816
|
||||
if (trgcpu == 4) {
|
||||
// is incompatible with nmos6502 with undocumented opcodes
|
||||
fprintf(stderr, "Error: file '%s' in CPU mode %d (%s) "
|
||||
fprintf(stderr,
|
||||
"Error: file '%s' in CPU mode %d (%s) "
|
||||
"is incompatible with previous files with mode %d (%s)\n",
|
||||
file->fname, fcpu, cpunames[fcpu], trgcpu, cpunames[trgcpu]);
|
||||
file->fname, fcpu, cpunames[fcpu], trgcpu,
|
||||
cpunames[trgcpu]);
|
||||
er = 1;
|
||||
}
|
||||
break;
|
||||
|
@ -393,9 +417,11 @@ int main(int argc, char *argv[]) {
|
|||
case 0x5: // 65816 in 6502 emulation mode
|
||||
if (trgcpu == 1 || trgcpu == 3) {
|
||||
// 65C02 and 65CE02 are incompatible with nmos6502 with undocumented opcodes
|
||||
fprintf(stderr, "Error: file '%s' in CPU mode %d (%s) is "
|
||||
fprintf(stderr,
|
||||
"Error: file '%s' in CPU mode %d (%s) is "
|
||||
"incompatible with previous files with mode %d (%s)\n",
|
||||
file->fname, fcpu, cpunames[fcpu], trgcpu, cpunames[trgcpu]);
|
||||
file->fname, fcpu, cpunames[fcpu], trgcpu,
|
||||
cpunames[trgcpu]);
|
||||
er = 1;
|
||||
}
|
||||
break;
|
||||
|
@ -403,20 +429,24 @@ int main(int argc, char *argv[]) {
|
|||
case 0x4: // NMOS 6502 with undocumented opcodes
|
||||
if (trgcpu == 1 || trgcpu == 2 || trgcpu == 3 || trgcpu == 5) {
|
||||
// is incompatible with nmos6502 with undocumented opcodes
|
||||
fprintf(stderr, "Error: file '%s' in CPU mode %d (%s) is "
|
||||
fprintf(stderr,
|
||||
"Error: file '%s' in CPU mode %d (%s) is "
|
||||
"incompatible with previous files with mode %d (%s)\n",
|
||||
file->fname, fcpu, cpunames[fcpu], trgcpu, cpunames[trgcpu]);
|
||||
file->fname, fcpu, cpunames[fcpu], trgcpu,
|
||||
cpunames[trgcpu]);
|
||||
er = 1;
|
||||
}
|
||||
if (trgmode & 0x8000) {
|
||||
fprintf(stderr, "Error: file '%s' in mode %d (%s) is incompatible with previous 65816 CPU mode\n",
|
||||
fprintf(stderr,
|
||||
"Error: file '%s' in mode %d (%s) is incompatible with previous 65816 CPU mode\n",
|
||||
file->fname, 4, cpunames[4]);
|
||||
er = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (fcpu > 5) {
|
||||
printf("Warning: unknown CPU mode %d (%s) detected in file %s\n",
|
||||
printf(
|
||||
"Warning: unknown CPU mode %d (%s) detected in file %s\n",
|
||||
fcpu, cpunames[fcpu], file->fname);
|
||||
}
|
||||
break;
|
||||
|
@ -448,8 +478,7 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
}
|
||||
if (verbose && !er) {
|
||||
printf("... to new target %s (%d)\n",
|
||||
cpunames[trgcpu], trgcpu);
|
||||
printf("... to new target %s (%d)\n", cpunames[trgcpu], trgcpu);
|
||||
}
|
||||
}
|
||||
if (er) {
|
||||
|
@ -474,7 +503,6 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// step 2 - calculate new segment base addresses per file, by
|
||||
// concatenating the segments per type
|
||||
|
@ -483,7 +511,6 @@ int main(int argc, char *argv[]) {
|
|||
/* set total length to zero */
|
||||
ttlen = tdlen = tblen = tzlen = 0;
|
||||
|
||||
|
||||
// then check start addresses
|
||||
file = fp[0];
|
||||
if (file->align != 0) {
|
||||
|
@ -555,15 +582,24 @@ printf("zbase=%04x+len=%04x->%04x, file->zbase=%04x, f.zlen=%04x -> zdiff=%04x\n
|
|||
*/
|
||||
|
||||
if (verbose > 0) {
|
||||
printf("Relocating file: %s [CPU %s]\n", file->fname, cpunames[((file->mode & FM_CPU2) >> 4) & 0x0f]);
|
||||
printf(" text: align fill %04x, relocate from %04x to %04x (diff is %04x, length is %04x)\n",
|
||||
file->talign, file->tbase, file->tbase + file->tdiff, file->tdiff, file->tlen);
|
||||
printf(" data: align fill %04x, relocate from %04x to %04x (diff is %04x, length is %04x)\n",
|
||||
file->dalign, file->dbase, file->dbase + file->ddiff, file->ddiff, file->dlen);
|
||||
printf(" bss: align fill %04x, relocate from %04x to %04x (diff is %04x, length is %04x)\n",
|
||||
file->balign, file->bbase, file->bbase + file->bdiff, file->bdiff, file->blen);
|
||||
printf(" zero: relocate from %02x to %02x (diff is %02x, length is %02x)\n",
|
||||
file->zbase, file->zbase + file->zdiff, file->zdiff, file->zlen);
|
||||
printf("Relocating file: %s [CPU %s]\n", file->fname,
|
||||
cpunames[((file->mode & FM_CPU2) >> 4) & 0x0f]);
|
||||
printf(
|
||||
" text: align fill %04x, relocate from %04x to %04x (diff is %04x, length is %04x)\n",
|
||||
file->talign, file->tbase, file->tbase + file->tdiff,
|
||||
file->tdiff, file->tlen);
|
||||
printf(
|
||||
" data: align fill %04x, relocate from %04x to %04x (diff is %04x, length is %04x)\n",
|
||||
file->dalign, file->dbase, file->dbase + file->ddiff,
|
||||
file->ddiff, file->dlen);
|
||||
printf(
|
||||
" bss: align fill %04x, relocate from %04x to %04x (diff is %04x, length is %04x)\n",
|
||||
file->balign, file->bbase, file->bbase + file->bdiff,
|
||||
file->bdiff, file->blen);
|
||||
printf(
|
||||
" zero: relocate from %02x to %02x (diff is %02x, length is %02x)\n",
|
||||
file->zbase, file->zbase + file->zdiff, file->zdiff,
|
||||
file->zlen);
|
||||
}
|
||||
|
||||
/* update globals (for result file) */
|
||||
|
@ -640,7 +676,6 @@ printf("zbase=%04x+len=%04x->%04x, file->zbase=%04x, f.zlen=%04x -> zdiff=%04x\n
|
|||
read_globals(file);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// step 4 - for each file, resolve undefined lables, storing replacement info
|
||||
// in the ud label table; merge remaining undefined labels into global
|
||||
|
@ -698,15 +733,8 @@ printf("zbase=%04x+len=%04x->%04x, file->zbase=%04x, f.zlen=%04x -> zdiff=%04x\n
|
|||
&tro, // pointer in output reloc bufer
|
||||
file);
|
||||
|
||||
reloc_seg(file->buf,
|
||||
file->dpos,
|
||||
file->dbase,
|
||||
file->ddiff,
|
||||
file->drpos,
|
||||
dreloc,
|
||||
&lastdaddr,
|
||||
&dro,
|
||||
file);
|
||||
reloc_seg(file->buf, file->dpos, file->dbase, file->ddiff, file->drpos,
|
||||
dreloc, &lastdaddr, &dro, file);
|
||||
|
||||
// change file information to relocated values
|
||||
file->tbase += file->tdiff;
|
||||
|
@ -743,22 +771,32 @@ printf("zbase=%04x+len=%04x->%04x, file->zbase=%04x, f.zlen=%04x -> zdiff=%04x\n
|
|||
//
|
||||
|
||||
// prepare header
|
||||
hdr[ 6] = trgmode & 255; hdr[ 7] = (trgmode>>8)& 255;
|
||||
hdr[ 8] = tbase & 255; hdr[ 9] = (tbase>>8) & 255;
|
||||
hdr[10] = ttlen & 255; hdr[11] = (ttlen >>8)& 255;
|
||||
hdr[12] = dbase & 255; hdr[13] = (dbase>>8) & 255;
|
||||
hdr[14] = tdlen & 255; hdr[15] = (tdlen >>8)& 255;
|
||||
hdr[16] = bbase & 255; hdr[17] = (bbase>>8) & 255;
|
||||
hdr[18] = tblen & 255; hdr[19] = (tblen >>8)& 255;
|
||||
hdr[20] = zbase & 255; hdr[21] = (zbase>>8) & 255;
|
||||
hdr[22] = tzlen & 255; hdr[23] = (tzlen >>8)& 255;
|
||||
hdr[24] = 0; hdr[25] = 0;
|
||||
hdr[6] = trgmode & 255;
|
||||
hdr[7] = (trgmode >> 8) & 255;
|
||||
hdr[8] = tbase & 255;
|
||||
hdr[9] = (tbase >> 8) & 255;
|
||||
hdr[10] = ttlen & 255;
|
||||
hdr[11] = (ttlen >> 8) & 255;
|
||||
hdr[12] = dbase & 255;
|
||||
hdr[13] = (dbase >> 8) & 255;
|
||||
hdr[14] = tdlen & 255;
|
||||
hdr[15] = (tdlen >> 8) & 255;
|
||||
hdr[16] = bbase & 255;
|
||||
hdr[17] = (bbase >> 8) & 255;
|
||||
hdr[18] = tblen & 255;
|
||||
hdr[19] = (tblen >> 8) & 255;
|
||||
hdr[20] = zbase & 255;
|
||||
hdr[21] = (zbase >> 8) & 255;
|
||||
hdr[22] = tzlen & 255;
|
||||
hdr[23] = (tzlen >> 8) & 255;
|
||||
hdr[24] = 0;
|
||||
hdr[25] = 0;
|
||||
|
||||
// open file
|
||||
fd = fopen(outfile, "wb");
|
||||
if (!fd) {
|
||||
fprintf(stderr,"Couldn't open output file %s (%s)\n",
|
||||
outfile, strerror(errno));
|
||||
fprintf(stderr, "Couldn't open output file %s (%s)\n", outfile,
|
||||
strerror(errno));
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
@ -864,7 +902,8 @@ int read_undef(unsigned char *buf, file65 *file) {
|
|||
while (i < nlabels) {
|
||||
// find length of label name
|
||||
startp = bufp;
|
||||
while(buf[bufp++]);
|
||||
while (buf[bufp++])
|
||||
;
|
||||
// store label info
|
||||
current = &file->ud[i];
|
||||
current->name = (char*) buf + startp;
|
||||
|
@ -907,7 +946,6 @@ printf("resolved undef label %s to: resolved=%d, newidx=%d\n", current->name, cu
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int write_undef(FILE *f, file65 *fp) {
|
||||
int i;
|
||||
for (i = 0; i < fp->nundef; i++) {
|
||||
|
@ -948,7 +986,6 @@ int check_undef(file65 *fp, char *defined[], int ndefined) {
|
|||
return er;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* compute and return the length of the relocation table */
|
||||
|
@ -973,7 +1010,8 @@ int len_reloc_seg(unsigned char *buf, int ri) {
|
|||
case 0x20:
|
||||
break;
|
||||
}
|
||||
if(seg==0) ri+=2;
|
||||
if (seg == 0)
|
||||
ri += 2;
|
||||
}
|
||||
}
|
||||
return ++ri;
|
||||
|
@ -990,13 +1028,14 @@ unsigned char *reloc_globals(unsigned char *buf, file65 *fp) {
|
|||
|
||||
while (n) {
|
||||
name = buf;
|
||||
while(*(buf++));
|
||||
while (*(buf++))
|
||||
;
|
||||
seg = *buf & 0x07;
|
||||
old = buf[1] + 256 * buf[2];
|
||||
new = old + reldiff(seg);
|
||||
if (verbose > 1) {
|
||||
printf("%s:%s: old=%04x, seg=%d, rel=%04x, new=%04x\n",
|
||||
fp->fname, name, old, seg, reldiff(seg), new);
|
||||
printf("%s:%s: old=%04x, seg=%d, rel=%04x, new=%04x\n", fp->fname,
|
||||
name, old, seg, reldiff(seg), new);
|
||||
}
|
||||
buf[1] = new & 255;
|
||||
buf[2] = (new >> 8) & 255;
|
||||
|
@ -1044,13 +1083,18 @@ file65 *load_file(char *fname) {
|
|||
mode = file->buf[7] * 256 + file->buf[6];
|
||||
file->mode = mode;
|
||||
if (mode & 0x2000) {
|
||||
fprintf(stderr,"file65: %s: 32 bit size not supported\n", fname);
|
||||
free(file->buf); free(file); file=NULL;
|
||||
} else
|
||||
if(mode & 0x4000) {
|
||||
fprintf(stderr,"file65: %s: pagewise relocation not supported\n",
|
||||
fprintf(stderr, "file65: %s: 32 bit size not supported\n",
|
||||
fname);
|
||||
free(file->buf); free(file); file=NULL;
|
||||
free(file->buf);
|
||||
free(file);
|
||||
file = NULL;
|
||||
} else if (mode & 0x4000) {
|
||||
fprintf(stderr,
|
||||
"file65: %s: pagewise relocation not supported\n",
|
||||
fname);
|
||||
free(file->buf);
|
||||
free(file);
|
||||
file = NULL;
|
||||
} else {
|
||||
|
||||
align = mode & 3;
|
||||
|
@ -1090,7 +1134,8 @@ file65 *load_file(char *fname) {
|
|||
file->tpos = hlen;
|
||||
file->dpos = hlen + file->tlen;
|
||||
file->upos = file->dpos + file->dlen;
|
||||
file->trpos= file->upos + read_undef(file->buf+file->upos, file);
|
||||
file->trpos = file->upos
|
||||
+ read_undef(file->buf + file->upos, file);
|
||||
file->drpos = len_reloc_seg(file->buf, file->trpos);
|
||||
file->gpos = len_reloc_seg(file->buf, file->drpos);
|
||||
}
|
||||
|
@ -1114,7 +1159,6 @@ int g=0;
|
|||
// number of globals for which memory is already allocated
|
||||
int gm = 0;
|
||||
|
||||
|
||||
int write_globals(FILE *fp) {
|
||||
int i;
|
||||
|
||||
|
@ -1122,8 +1166,8 @@ int write_globals(FILE *fp) {
|
|||
fputc((g >> 8) & 255, fp);
|
||||
|
||||
for (i = 0; i < g; i++) {
|
||||
fprintf(fp,"%s%c%c%c%c",gp[i].name,0,gp[i].seg,
|
||||
gp[i].val & 255, (gp[i].val>>8)&255);
|
||||
fprintf(fp, "%s%c%c%c%c", gp[i].name, 0, gp[i].seg, gp[i].val & 255,
|
||||
(gp[i].val >> 8) & 255);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1160,7 +1204,9 @@ int write_nglobals(FILE *fp, char **globdef, int nglobal) {
|
|||
}
|
||||
if (i >= g) {
|
||||
// not found
|
||||
fprintf(stderr,"Warning: command line allowed global '%s' is not defined!\n", globdef[j]);
|
||||
fprintf(stderr,
|
||||
"Warning: command line allowed global '%s' is not defined!\n",
|
||||
globdef[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1170,8 +1216,8 @@ int write_nglobals(FILE *fp, char **globdef, int nglobal) {
|
|||
|
||||
for (i = 0; i < g; i++) {
|
||||
if (gp[i].name != NULL) {
|
||||
fprintf(fp,"%s%c%c%c%c",gp[i].name,0,gp[i].seg,
|
||||
gp[i].val & 255, (gp[i].val>>8)&255);
|
||||
fprintf(fp, "%s%c%c%c%c", gp[i].name, 0, gp[i].seg, gp[i].val & 255,
|
||||
(gp[i].val >> 8) & 255);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -1189,7 +1235,8 @@ int read_globals(file65 *fp) {
|
|||
/*printf("reading %s, ", buf);*/
|
||||
name = (char*) buf;
|
||||
l = 0;
|
||||
while(buf[l++]);
|
||||
while (buf[l++])
|
||||
;
|
||||
buf += l;
|
||||
ll = l - 1;
|
||||
seg = *buf;
|
||||
|
@ -1200,7 +1247,8 @@ int read_globals(file65 *fp) {
|
|||
/* multiply defined? */
|
||||
for (i = 0; i < g; i++) {
|
||||
if (ll == gp[i].len && !strcmp(name, gp[i].name)) {
|
||||
fprintf(stderr,"Warning: label '%s' multiply defined (%s and %s)\n",
|
||||
fprintf(stderr,
|
||||
"Warning: label '%s' multiply defined (%s and %s)\n",
|
||||
name, fp->fname, gp[i].file->fname);
|
||||
gp[i].fl = 1;
|
||||
break;
|
||||
|
@ -1216,7 +1264,8 @@ int read_globals(file65 *fp) {
|
|||
}
|
||||
}
|
||||
if (g >= 0x10000) {
|
||||
fprintf(stderr,"Outch, maximum number of labels (65536) exceeded!\n");
|
||||
fprintf(stderr,
|
||||
"Outch, maximum number of labels (65536) exceeded!\n");
|
||||
exit(3);
|
||||
}
|
||||
gp[g].name = name;
|
||||
|
@ -1264,13 +1313,13 @@ int find_file_global(unsigned char *bp, file65 *fp, int *seg) {
|
|||
for (i = 0; i < g; i++) {
|
||||
if (gp[i].len == l && !strcmp(gp[i].name, n)) {
|
||||
*seg = gp[i].seg;
|
||||
bp[0] = i & 255; bp[1] = (i>>8) & 255;
|
||||
bp[0] = i & 255;
|
||||
bp[1] = (i >> 8) & 255;
|
||||
/*printf("return gp[%d]=%s (len=%d), val=%04x\n",i,gp[i].name,gp[i].len,gp[i].val);*/
|
||||
return gp[i].val;
|
||||
}
|
||||
}
|
||||
fprintf(stderr,"Warning: undefined label '%s' in file %s\n",
|
||||
n, fp->fname);
|
||||
fprintf(stderr, "Warning: undefined label '%s' in file %s\n", n, fp->fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1446,5 +1495,3 @@ printf("found undef'd label %s, resolved=%d, newidx=%d, (ri=%d, ro=%d)\n", u->na
|
|||
return ++ri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* printcbm -- A part of xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
* list CBM BASIC programs
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -54,8 +54,7 @@ void usage(FILE *fp)
|
|||
programname);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *fp;
|
||||
int a, b, c;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* reloc65 -- A part of xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
* o65 file relocator
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -131,7 +131,8 @@ int main(int argc, char *argv[]) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if (strstr(argv[1], "--help") || strstr(argv[1], "-?") || strstr(argv[1], "-h")) {
|
||||
if (strstr(argv[1], "--help") || strstr(argv[1], "-?")
|
||||
|| strstr(argv[1], "-h")) {
|
||||
usage(stdout);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -150,9 +151,12 @@ int main(int argc, char *argv[]) {
|
|||
verbose = 1;
|
||||
break;
|
||||
case 'o':
|
||||
if(argv[i][2]) outfile=argv[i]+2;
|
||||
else if(i + 1 < argc) outfile=argv[++i];
|
||||
else fprintf(stderr,"%s: missing output file\n",programname);
|
||||
if (argv[i][2])
|
||||
outfile = argv[i] + 2;
|
||||
else if (i + 1 < argc)
|
||||
outfile = argv[++i];
|
||||
else
|
||||
fprintf(stderr, "%s: missing output file\n", programname);
|
||||
break;
|
||||
case 'X':
|
||||
extract = 3;
|
||||
|
@ -177,13 +181,17 @@ int main(int argc, char *argv[]) {
|
|||
base = &zbase;
|
||||
break;
|
||||
default:
|
||||
printf("Unknown segment type '%c' - ignored!\n", argv[i][2]);
|
||||
printf("Unknown segment type '%c' - ignored!\n",
|
||||
argv[i][2]);
|
||||
break;
|
||||
}
|
||||
if (base != NULL) {
|
||||
if(argv[i][3]) *base = atoi(argv[i]+3);
|
||||
else if(i + 1 < argc) *base = atoi(argv[++i]);
|
||||
else fprintf(stderr,"%s: missing address\n",programname);
|
||||
if (argv[i][3])
|
||||
*base = atoi(argv[i] + 3);
|
||||
else if (i + 1 < argc)
|
||||
*base = atoi(argv[++i]);
|
||||
else
|
||||
fprintf(stderr, "%s: missing address\n", programname);
|
||||
}
|
||||
break;
|
||||
case 'x': /* extract segment */
|
||||
|
@ -196,16 +204,20 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
case 'z':
|
||||
case 'b':
|
||||
printf("Cannot extract segment type '%c' - ignored!\n", argv[i][2]);
|
||||
printf("Cannot extract segment type '%c' - ignored!\n",
|
||||
argv[i][2]);
|
||||
break;
|
||||
default:
|
||||
printf("Unknown segment type '%c' - ignored!\n", argv[i][2]);
|
||||
printf("Unknown segment type '%c' - ignored!\n",
|
||||
argv[i][2]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
if(argv[i][2]) arg=argv[i]+2;
|
||||
else if(i + 1 < argc) arg=argv[++i];
|
||||
if (argv[i][2])
|
||||
arg = argv[i] + 2;
|
||||
else if (i + 1 < argc)
|
||||
arg = argv[++i];
|
||||
if (arg == NULL) {
|
||||
printf("Missing CPU parameter to -C - ignored\n");
|
||||
break;
|
||||
|
@ -223,7 +235,8 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"%s: %s unknown option, use '-h' for help\n",programname,argv[i]);
|
||||
fprintf(stderr, "%s: %s unknown option, use '-h' for help\n",
|
||||
programname, argv[i]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -244,10 +257,13 @@ int main(int argc, char *argv[]) {
|
|||
if ((n >= file.fsize) && (!memcmp(file.buf, cmp, 5))) {
|
||||
mode = file.buf[7] * 256 + file.buf[6];
|
||||
if (mode & FM_SIZE) {
|
||||
fprintf(stderr,"reloc65: %s: 32 bit size not supported\n", argv[i]);
|
||||
} else
|
||||
if(mode & FM_RELOC) {
|
||||
fprintf(stderr,"reloc65: %s: pagewise relocation not supported\n", argv[i]);
|
||||
fprintf(stderr,
|
||||
"reloc65: %s: 32 bit size not supported\n",
|
||||
argv[i]);
|
||||
} else if (mode & FM_RELOC) {
|
||||
fprintf(stderr,
|
||||
"reloc65: %s: pagewise relocation not supported\n",
|
||||
argv[i]);
|
||||
} else {
|
||||
if (trgcpu >= 0) {
|
||||
// change CPU flags
|
||||
|
@ -274,7 +290,9 @@ int main(int argc, char *argv[]) {
|
|||
file.ddiff = dflag ? dbase - file.dbase : 0;
|
||||
if (extract == 3) {
|
||||
if (dflag) {
|
||||
fprintf(stderr,"reloc65: %s: Warning: data segment address overrides -X option\n", argv[i]);
|
||||
fprintf(stderr,
|
||||
"reloc65: %s: Warning: data segment address overrides -X option\n",
|
||||
argv[i]);
|
||||
} else {
|
||||
dbase = file.tbase + file.tdiff + file.tlen;
|
||||
file.ddiff = dbase - file.dbase;
|
||||
|
@ -286,7 +304,9 @@ int main(int argc, char *argv[]) {
|
|||
file.bdiff = bflag ? bbase - file.bbase : 0;
|
||||
if (extract == 3) {
|
||||
if (bflag) {
|
||||
fprintf(stderr,"reloc65: %s: Warning: bss segment address overrides -X option\n", argv[i]);
|
||||
fprintf(stderr,
|
||||
"reloc65: %s: Warning: bss segment address overrides -X option\n",
|
||||
argv[i]);
|
||||
} else {
|
||||
bbase = file.dbase + file.ddiff + file.dlen;
|
||||
file.bdiff = bbase - file.bbase;
|
||||
|
@ -299,18 +319,30 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
if (verbose) {
|
||||
printf("Relocating segments to:\n");
|
||||
printf("text segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.tbase + file.tdiff, file.tbase + file.tdiff + file.tlen,
|
||||
file.tlen, file.tlen, file.tdiff, file.tdiff & 0xffff);
|
||||
printf("data segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.dbase + file.ddiff, file.dbase + file.ddiff + file.dlen,
|
||||
file.dlen, file.dlen, file.ddiff, file.ddiff & 0xffff);
|
||||
printf("bss segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.bbase + file.bdiff, file.bbase + file.bdiff + file.blen,
|
||||
file.blen, file.blen, file.bdiff, file.bdiff & 0xffff);
|
||||
printf("zero segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.zbase + file.zdiff, file.zbase + file.zdiff + file.zlen,
|
||||
file.zlen, file.zlen, file.zdiff, file.zdiff & 0xffff);
|
||||
printf(
|
||||
"text segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.tbase + file.tdiff,
|
||||
file.tbase + file.tdiff + file.tlen,
|
||||
file.tlen, file.tlen, file.tdiff,
|
||||
file.tdiff & 0xffff);
|
||||
printf(
|
||||
"data segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.dbase + file.ddiff,
|
||||
file.dbase + file.ddiff + file.dlen,
|
||||
file.dlen, file.dlen, file.ddiff,
|
||||
file.ddiff & 0xffff);
|
||||
printf(
|
||||
"bss segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.bbase + file.bdiff,
|
||||
file.bbase + file.bdiff + file.blen,
|
||||
file.blen, file.blen, file.bdiff,
|
||||
file.bdiff & 0xffff);
|
||||
printf(
|
||||
"zero segment @ $%04x - $%04x, %5d ($%04x) bytes, diff is %5d ($%04x)\n",
|
||||
file.zbase + file.zdiff,
|
||||
file.zbase + file.zdiff + file.zlen,
|
||||
file.zlen, file.zlen, file.zdiff,
|
||||
file.zdiff & 0xffff);
|
||||
}
|
||||
|
||||
/* pointer of position in file */
|
||||
|
@ -368,16 +400,21 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
} else {
|
||||
fprintf(stderr, "reloc65: %s: not an o65 file!\n", argv[i]);
|
||||
if(file.buf[0]==1 && file.buf[1]==8 && file.buf[3]==8) {
|
||||
printf("%s: C64 BASIC executable (start address $0801)?\n", argv[i]);
|
||||
} else
|
||||
if(file.buf[0]==1 && file.buf[1]==4 && file.buf[3]==4) {
|
||||
printf("%s: CBM PET BASIC executable (start address $0401)?\n", argv[i]);
|
||||
if (file.buf[0] == 1 && file.buf[1] == 8
|
||||
&& file.buf[3] == 8) {
|
||||
printf(
|
||||
"%s: C64 BASIC executable (start address $0801)?\n",
|
||||
argv[i]);
|
||||
} else if (file.buf[0] == 1 && file.buf[1] == 4
|
||||
&& file.buf[3] == 4) {
|
||||
printf(
|
||||
"%s: CBM PET BASIC executable (start address $0401)?\n",
|
||||
argv[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,"reloc65: read '%s': %s\n",
|
||||
argv[i], strerror(errno));
|
||||
fprintf(stderr, "reloc65: read '%s': %s\n", argv[i],
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
i++;
|
||||
|
@ -385,7 +422,6 @@ int main(int argc, char *argv[]) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int read_options(unsigned char *buf) {
|
||||
int c, l = 0;
|
||||
|
||||
|
@ -454,14 +490,17 @@ unsigned char *reloc_seg(unsigned char *buf, int len, unsigned char *rtab,
|
|||
if (seg == 0) {
|
||||
/* undefined segment entry */
|
||||
if (undefwarn) {
|
||||
fprintf(stderr,"reloc65: %s: Warning: undefined relocation table entry not handled!\n", fp->fname);
|
||||
fprintf(stderr,
|
||||
"reloc65: %s: Warning: undefined relocation table entry not handled!\n",
|
||||
fp->fname);
|
||||
}
|
||||
rtab += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (adr > len) {
|
||||
fprintf(stderr,"reloc65: %s: Warning: relocation table entries past segment end!\n",
|
||||
fprintf(stderr,
|
||||
"reloc65: %s: Warning: relocation table entries past segment end!\n",
|
||||
fp->fname);
|
||||
fprintf(stderr, "reloc65: adr=%x len=%x\n", adr, len);
|
||||
}
|
||||
|
@ -476,7 +515,8 @@ unsigned char *reloc_globals(unsigned char *buf, file65 *fp) {
|
|||
|
||||
while (n) {
|
||||
/*printf("relocating %s, ", buf);*/
|
||||
while(*(buf++));
|
||||
while (*(buf++))
|
||||
;
|
||||
seg = *buf;
|
||||
old = buf[1] + 256 * buf[2];
|
||||
new = old + reldiff(seg);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* reloc65 -- A part of xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
* Pack/Unpack cpk archive files
|
||||
*
|
||||
* Copyright (C) 1989-2002 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-2002 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -54,8 +54,7 @@ void usage(FILE *fp)
|
|||
|
||||
int list=0,verbose=0,add=0,create=0;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
int i, c, c2, fileok, nc;
|
||||
size_t n, n2;
|
||||
FILE *fp, *fpo = NULL;
|
||||
|
@ -95,17 +94,19 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
if (add) {
|
||||
fpo = fopen(argv[2], "ab");
|
||||
} else
|
||||
if(create) {
|
||||
} else if (create) {
|
||||
fpo = fopen(argv[2], "wb");
|
||||
}
|
||||
if (fpo) {
|
||||
if(!add) fputc(1,fpo); /* Version Byte */
|
||||
if (!add)
|
||||
fputc(1, fpo); /* Version Byte */
|
||||
for (i = 3; i < argc; i++) {
|
||||
if(verbose) printf("%s\n",argv[i]);
|
||||
if (verbose)
|
||||
printf("%s\n", argv[i]);
|
||||
fp = fopen(argv[i], "rb");
|
||||
if (fp) {
|
||||
while((s=strchr(argv[i],':'))) *s='/';
|
||||
while ((s = strchr(argv[i], ':')))
|
||||
*s = '/';
|
||||
fprintf(fpo, "%s", argv[i]);
|
||||
fputc(0, fpo);
|
||||
c = fgetc(fp);
|
||||
|
@ -127,9 +128,11 @@ int main(int argc, char *argv[])
|
|||
c = c2;
|
||||
}
|
||||
fclose(fp);
|
||||
fputc(0xf7,fpo); fputc(0,fpo);
|
||||
fputc(0xf7, fpo);
|
||||
fputc(0, fpo);
|
||||
} else {
|
||||
fprintf(stderr,"Couldn't open file '%s' for reading!",argv[i]);
|
||||
fprintf(stderr, "Couldn't open file '%s' for reading!",
|
||||
argv[i]);
|
||||
}
|
||||
}
|
||||
fclose(fpo);
|
||||
|
@ -148,19 +151,24 @@ int main(int argc, char *argv[])
|
|||
/* read name */
|
||||
i = 0;
|
||||
while ((c = fgetc(fp))) {
|
||||
if(c==EOF) break;
|
||||
if (c == EOF)
|
||||
break;
|
||||
name[i++] = c;
|
||||
}
|
||||
name[i++] = '\0';
|
||||
if (!c) { /* end of archive ? */
|
||||
while((s=strchr(name,'/'))) *s=':';
|
||||
while ((s = strchr(name, '/')))
|
||||
*s = ':';
|
||||
|
||||
if(verbose+list) printf("%s\n",name);
|
||||
if (verbose + list)
|
||||
printf("%s\n", name);
|
||||
|
||||
if (!list) {
|
||||
fpo = fopen(name, "wb");
|
||||
if (!fpo) {
|
||||
fprintf(stderr,"Couldn't open output file %s !\n",name);
|
||||
fprintf(stderr,
|
||||
"Couldn't open output file %s !\n",
|
||||
name);
|
||||
}
|
||||
}
|
||||
fileok = 0;
|
||||
|
|
413
xa/src/xa.c
413
xa/src/xa.c
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* maintained by Cameron Kaiser (ckaiser@floodgap.com)
|
||||
*
|
||||
* Main program
|
||||
|
@ -117,8 +117,7 @@ int relmode=0;
|
|||
|
||||
int pc[SEG_MAX]; /* segments */
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
int er = 1, i;
|
||||
signed char *s = NULL;
|
||||
char *tmpp;
|
||||
|
@ -163,11 +162,8 @@ int main(int argc,char *argv[])
|
|||
} else {
|
||||
tmpp = argv[0];
|
||||
}
|
||||
if( (!strcmp(tmpp,"xa65816"))
|
||||
|| (!strcmp(tmpp,"XA65816"))
|
||||
|| (!strcmp(tmpp,"xa816"))
|
||||
|| (!strcmp(tmpp,"XA816"))
|
||||
) {
|
||||
if ((!strcmp(tmpp, "xa65816")) || (!strcmp(tmpp, "XA65816"))
|
||||
|| (!strcmp(tmpp, "xa816")) || (!strcmp(tmpp, "XA816"))) {
|
||||
w65816 = 1; /* allow 65816 per default */
|
||||
}
|
||||
|
||||
|
@ -219,7 +215,8 @@ int main(int argc,char *argv[])
|
|||
if (ca65) {
|
||||
collab = 0; /* paranoia */
|
||||
fprintf(stderr, "Warning: -a not needed with -XCA65\n");
|
||||
} else collab=1;
|
||||
} else
|
||||
collab = 1;
|
||||
break;
|
||||
case 'k':
|
||||
mask = 1;
|
||||
|
@ -244,7 +241,8 @@ int main(int argc,char *argv[])
|
|||
"warning: extra characters to -p ignored\n");
|
||||
break;
|
||||
case 'M':
|
||||
fprintf(stderr, "Warning: -M is deprecated (use -XMASM) and will be removed in a future version\n");
|
||||
fprintf(stderr,
|
||||
"Warning: -M is deprecated (use -XMASM) and will be removed in a future version\n");
|
||||
masm = 1; /* MASM compatibility mode */
|
||||
break;
|
||||
case 'X': /* compatibility across assemblers... */
|
||||
|
@ -256,7 +254,9 @@ int main(int argc,char *argv[])
|
|||
name = argv[i] + 2;
|
||||
}
|
||||
if (set_compat(name) < 0) {
|
||||
fprintf(stderr, "Compatibility set '%s' unknown - ignoring! (check case?)\n", name);
|
||||
fprintf(stderr,
|
||||
"Compatibility set '%s' unknown - ignoring! (check case?)\n",
|
||||
name);
|
||||
}
|
||||
if (collab && ca65) {
|
||||
collab = 0;
|
||||
|
@ -268,7 +268,8 @@ int main(int argc,char *argv[])
|
|||
{
|
||||
char *name = NULL;
|
||||
if (argv[i][2] == 0) {
|
||||
if (i + 1 < argc) name = argv[++i];
|
||||
if (i + 1 < argc)
|
||||
name = argv[++i];
|
||||
else {
|
||||
fprintf(stderr, "-O requires an argument\n");
|
||||
exit(1);
|
||||
|
@ -277,7 +278,9 @@ int main(int argc,char *argv[])
|
|||
name = argv[i] + 2;
|
||||
}
|
||||
if (set_charset(name) < 0) {
|
||||
fprintf(stderr, "Output charset name '%s' unknown - ignoring! (check case?)\n", name);
|
||||
fprintf(stderr,
|
||||
"Output charset name '%s' unknown - ignoring! (check case?)\n",
|
||||
name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -285,19 +288,21 @@ int main(int argc,char *argv[])
|
|||
is not necessary when _file_ starts at adr */
|
||||
romable = 2;
|
||||
if (argv[i][2] == 0) {
|
||||
if (i + 1 < argc) romaddr = atoi(argv[++i]);
|
||||
if (i + 1 < argc)
|
||||
romaddr = atoi(argv[++i]);
|
||||
else {
|
||||
fprintf(stderr, "-A requires an argument\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else romaddr = atoi(argv[i]+2);
|
||||
} else
|
||||
romaddr = atoi(argv[i] + 2);
|
||||
break;
|
||||
case 'G':
|
||||
noglob = 1;
|
||||
break;
|
||||
case 'L': /* define global label */
|
||||
if(argv[i][2]) lg_set(argv[i]+2);
|
||||
if (argv[i][2])
|
||||
lg_set(argv[i] + 2);
|
||||
break;
|
||||
case 'r':
|
||||
crossref = 1;
|
||||
|
@ -310,7 +315,8 @@ int main(int argc,char *argv[])
|
|||
break;
|
||||
case 'D':
|
||||
s = (signed char*) strstr(argv[i] + 2, "=");
|
||||
if(s) *s = ' ';
|
||||
if (s)
|
||||
*s = ' ';
|
||||
pp_define(argv[i] + 2);
|
||||
break;
|
||||
case 'c':
|
||||
|
@ -351,7 +357,8 @@ int main(int argc,char *argv[])
|
|||
break;
|
||||
case 'I':
|
||||
if (argv[i][2] == 0) {
|
||||
if (i + 1 < argc) reg_include(argv[++i]);
|
||||
if (i + 1 < argc)
|
||||
reg_include(argv[++i]);
|
||||
else {
|
||||
fprintf(stderr, "-I requires an argument\n");
|
||||
exit(1);
|
||||
|
@ -376,7 +383,8 @@ int main(int argc,char *argv[])
|
|||
break;
|
||||
case 'o':
|
||||
if (argv[i][2] == 0) {
|
||||
if (i + 1 < argc) ofile=argv[++i];
|
||||
if (i + 1 < argc)
|
||||
ofile = argv[++i];
|
||||
else {
|
||||
fprintf(stderr, "-o requires an argument\n");
|
||||
exit(1);
|
||||
|
@ -387,7 +395,8 @@ int main(int argc,char *argv[])
|
|||
break;
|
||||
case 'l':
|
||||
if (argv[i][2] == 0) {
|
||||
if (i + 1 < argc) lfile=argv[++i];
|
||||
if (i + 1 < argc)
|
||||
lfile = argv[++i];
|
||||
else {
|
||||
fprintf(stderr, "-l requires an argument\n");
|
||||
exit(1);
|
||||
|
@ -398,7 +407,8 @@ int main(int argc,char *argv[])
|
|||
break;
|
||||
case 'e':
|
||||
if (argv[i][2] == 0) {
|
||||
if (i + 1 < argc) efile=argv[++i];
|
||||
if (i + 1 < argc)
|
||||
efile = argv[++i];
|
||||
else {
|
||||
fprintf(stderr, "-e requires an argument\n");
|
||||
exit(1);
|
||||
|
@ -410,20 +420,28 @@ int main(int argc,char *argv[])
|
|||
case 'b': /* set segment base addresses */
|
||||
switch (argv[i][2]) {
|
||||
case 't':
|
||||
if(argv[i][3]==0) tbase = atoi(argv[++i]);
|
||||
else tbase = atoi(argv[i]+3);
|
||||
if (argv[i][3] == 0)
|
||||
tbase = atoi(argv[++i]);
|
||||
else
|
||||
tbase = atoi(argv[i] + 3);
|
||||
break;
|
||||
case 'd':
|
||||
if(argv[i][3]==0) dbase = atoi(argv[++i]);
|
||||
else dbase = atoi(argv[i]+3);
|
||||
if (argv[i][3] == 0)
|
||||
dbase = atoi(argv[++i]);
|
||||
else
|
||||
dbase = atoi(argv[i] + 3);
|
||||
break;
|
||||
case 'b':
|
||||
if(argv[i][3]==0) bbase = atoi(argv[++i]);
|
||||
else bbase = atoi(argv[i]+3);
|
||||
if (argv[i][3] == 0)
|
||||
bbase = atoi(argv[++i]);
|
||||
else
|
||||
bbase = atoi(argv[i] + 3);
|
||||
break;
|
||||
case 'z':
|
||||
if(argv[i][3]==0) zbase = atoi(argv[++i]);
|
||||
else zbase = atoi(argv[i]+3);
|
||||
if (argv[i][3] == 0)
|
||||
zbase = atoi(argv[++i]);
|
||||
else
|
||||
zbase = atoi(argv[i] + 3);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown segment type '%c' - ignoring!\n",
|
||||
|
@ -432,10 +450,12 @@ int main(int argc,char *argv[])
|
|||
}
|
||||
break;
|
||||
case 0:
|
||||
fprintf(stderr, "Single dash '-' on command line - ignoring!\n");
|
||||
fprintf(stderr,
|
||||
"Single dash '-' on command line - ignoring!\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option '%c' - ignoring!\n",argv[i][1]);
|
||||
fprintf(stderr, "Unknown option '%c' - ignoring!\n",
|
||||
argv[i][1]);
|
||||
break;
|
||||
}
|
||||
} else { /* no option -> filename */
|
||||
|
@ -444,7 +464,8 @@ int main(int argc,char *argv[])
|
|||
mifiles += 5;
|
||||
ifiles = realloc(ifiles, mifiles * sizeof(char*));
|
||||
if (!ifiles) {
|
||||
fprintf(stderr, "Oops: couldn't alloc enough mem for filelist table..!\n");
|
||||
fprintf(stderr,
|
||||
"Oops: couldn't alloc enough mem for filelist table..!\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -456,7 +477,8 @@ int main(int argc,char *argv[])
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if(verbose) fprintf(stderr, "%s\n",copyright);
|
||||
if (verbose)
|
||||
fprintf(stderr, "%s\n", copyright);
|
||||
|
||||
if (printfile != NULL && !strcmp(printfile, "-")) {
|
||||
printfile = NULL;
|
||||
|
@ -477,27 +499,26 @@ int main(int argc,char *argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
if(verbose) fprintf(stderr, "%s\n",copyright);
|
||||
if (verbose)
|
||||
fprintf(stderr, "%s\n", copyright);
|
||||
|
||||
if(1 /*!m_init()*/)
|
||||
{
|
||||
if(1 /*!b_init()*/)
|
||||
{
|
||||
if(1 /*!l_init()*/)
|
||||
{
|
||||
if (1 /*!m_init()*/) {
|
||||
if (1 /*!b_init()*/) {
|
||||
if (1 /*!l_init()*/) {
|
||||
/*if(!pp_init())*/
|
||||
{
|
||||
if(!x_init())
|
||||
{
|
||||
if (!x_init()) {
|
||||
/* if(fperr) fprintf(fperr,"%s\n",copyright); */
|
||||
if(verbose) logout(ctime(&tim1));
|
||||
if (verbose)
|
||||
logout(ctime(&tim1));
|
||||
|
||||
list_setfile(fplist);
|
||||
|
||||
/* Pass 1 */
|
||||
|
||||
pc[SEG_ABS] = 0; /* abs addressing */
|
||||
seg_start(fmode, tbase, dbase, bbase, zbase, 0, relmode);
|
||||
seg_start(fmode, tbase, dbase, bbase, zbase, 0,
|
||||
relmode);
|
||||
|
||||
if (relmode) {
|
||||
r_mode(RMODE_RELOC);
|
||||
|
@ -510,62 +531,79 @@ int main(int argc,char *argv[])
|
|||
|
||||
nolink = no_link;
|
||||
|
||||
for (i=0; i<nifiles; i++)
|
||||
{
|
||||
for (i = 0; i < nifiles; i++) {
|
||||
ifile = ifiles[i];
|
||||
|
||||
sprintf(out, "xAss65: Pass 1: %s\n", ifile);
|
||||
if(verbose) logout(out);
|
||||
if (verbose)
|
||||
logout(out);
|
||||
|
||||
er = pp_open(ifile);
|
||||
puttmpw(0);
|
||||
puttmp(T_FILE);
|
||||
puttmp(0);
|
||||
puttmp(0);
|
||||
puttmps((signed char*)&ifile, sizeof(filep->fname));
|
||||
puttmps((signed char*) &ifile,
|
||||
sizeof(filep->fname));
|
||||
|
||||
if (!er) {
|
||||
er = pass1();
|
||||
pp_close();
|
||||
} else {
|
||||
sprintf(out, "Couldn't open source file '%s'!\n", ifile);
|
||||
sprintf(out,
|
||||
"Couldn't open source file '%s'!\n",
|
||||
ifile);
|
||||
logout(out);
|
||||
}
|
||||
}
|
||||
|
||||
if ((er = b_depth())) {
|
||||
sprintf(out,"Still %d blocks open at end of file!\n",er);
|
||||
sprintf(out,
|
||||
"Still %d blocks open at end of file!\n",
|
||||
er);
|
||||
logout(out);
|
||||
}
|
||||
|
||||
if (tbase & (align - 1)) {
|
||||
sprintf(out,"Warning: text segment ($%04x) start address doesn't align to %d!\n", tbase, align);
|
||||
sprintf(out,
|
||||
"Warning: text segment ($%04x) start address doesn't align to %d!\n",
|
||||
tbase, align);
|
||||
logout(out);
|
||||
}
|
||||
if (dbase & (align - 1)) {
|
||||
sprintf(out,"Warning: data segment ($%04x) start address doesn't align to %d!\n", dbase, align);
|
||||
sprintf(out,
|
||||
"Warning: data segment ($%04x) start address doesn't align to %d!\n",
|
||||
dbase, align);
|
||||
logout(out);
|
||||
}
|
||||
if (bbase & (align - 1)) {
|
||||
sprintf(out,"Warning: bss segment ($%04x) start address doesn't align to %d!\n", bbase, align);
|
||||
sprintf(out,
|
||||
"Warning: bss segment ($%04x) start address doesn't align to %d!\n",
|
||||
bbase, align);
|
||||
logout(out);
|
||||
}
|
||||
if (n65816 > 0)
|
||||
fmode |= 0x8000;
|
||||
switch (align) {
|
||||
case 1: break;
|
||||
case 2: fmode |= 1; break;
|
||||
case 4: fmode |= 2; break;
|
||||
case 256: fmode |=3; break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
fmode |= 1;
|
||||
break;
|
||||
case 4:
|
||||
fmode |= 2;
|
||||
break;
|
||||
case 256:
|
||||
fmode |= 3;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((!er) && relmode)
|
||||
h_write(fpout, fmode, tlen, dlen, blen, zlen, 0);
|
||||
|
||||
|
||||
if(!er)
|
||||
{
|
||||
if(verbose) logout("xAss65: Pass 2:\n");
|
||||
if (!er) {
|
||||
if (verbose)
|
||||
logout("xAss65: Pass 2:\n");
|
||||
|
||||
list_start(listformat);
|
||||
|
||||
|
@ -584,16 +622,23 @@ int main(int argc,char *argv[])
|
|||
list_end();
|
||||
}
|
||||
|
||||
if(fplab) printllist(fplab);
|
||||
if (fplab)
|
||||
printllist(fplab);
|
||||
tim2 = time(NULL);
|
||||
if(verbose) printstat();
|
||||
if (verbose)
|
||||
printstat();
|
||||
|
||||
if((!er) && relmode) seg_end(fpout); /* write reloc/label info */
|
||||
if ((!er) && relmode)
|
||||
seg_end(fpout); /* write reloc/label info */
|
||||
|
||||
if(fplist && fplist!=stdout) fclose(fplist);
|
||||
if(fperr) fclose(fperr);
|
||||
if(fplab) fclose(fplab);
|
||||
if(fpout && fpout!=stdout) fclose(fpout);
|
||||
if (fplist && fplist != stdout)
|
||||
fclose(fplist);
|
||||
if (fperr)
|
||||
fclose(fperr);
|
||||
if (fplab)
|
||||
fclose(fplab);
|
||||
if (fpout && fpout != stdout)
|
||||
fclose(fpout);
|
||||
|
||||
} else {
|
||||
logout("fatal: x: no memory!\n");
|
||||
|
@ -613,8 +658,7 @@ int main(int argc,char *argv[])
|
|||
logout("Not enough memory available!\n");
|
||||
}
|
||||
|
||||
if(ner || er)
|
||||
{
|
||||
if (ner || er) {
|
||||
if (ner_max > 0) {
|
||||
fprintf(stderr, "Break after %d error%c\n", ner, ner ? 's' : 0);
|
||||
} else {
|
||||
|
@ -632,39 +676,41 @@ int main(int argc,char *argv[])
|
|||
return ((er || ner) ? 1 : 0);
|
||||
}
|
||||
|
||||
static void printstat(void)
|
||||
{
|
||||
static void printstat(void) {
|
||||
logout("Statistics:\n");
|
||||
sprintf(out," %8d of %8d label used\n",ga_lab(),gm_lab()); logout(out);
|
||||
sprintf(out," %8ld of %8ld byte label-memory used\n",ga_labm(),gm_labm()); logout(out);
|
||||
sprintf(out," %8d of %8d PP-defs used\n",ga_pp(),gm_pp()); logout(out);
|
||||
sprintf(out," %8ld of %8ld byte PP-memory used\n",ga_ppm(),gm_ppm()); logout(out);
|
||||
sprintf(out," %8ld of %8ld byte buffer memory used\n",ga_p1(),gm_p1()); logout(out);
|
||||
sprintf(out," %8d blocks used\n",ga_blk()); logout(out);
|
||||
sprintf(out," %8ld seconds used\n",(long)difftime(tim2,tim1)); logout(out);
|
||||
sprintf(out, " %8d of %8d label used\n", ga_lab(), gm_lab());
|
||||
logout(out);
|
||||
sprintf(out, " %8ld of %8ld byte label-memory used\n", ga_labm(),
|
||||
gm_labm());
|
||||
logout(out);
|
||||
sprintf(out, " %8d of %8d PP-defs used\n", ga_pp(), gm_pp());
|
||||
logout(out);
|
||||
sprintf(out, " %8ld of %8ld byte PP-memory used\n", ga_ppm(), gm_ppm());
|
||||
logout(out);
|
||||
sprintf(out, " %8ld of %8ld byte buffer memory used\n", ga_p1(), gm_p1());
|
||||
logout(out);
|
||||
sprintf(out, " %8d blocks used\n", ga_blk());
|
||||
logout(out);
|
||||
sprintf(out, " %8ld seconds used\n", (long) difftime(tim2, tim1));
|
||||
logout(out);
|
||||
}
|
||||
|
||||
int h_length(void) {
|
||||
return 26 + o_length();
|
||||
}
|
||||
|
||||
|
||||
static int setfext(char *s, char *ext)
|
||||
{
|
||||
static int setfext(char *s, char *ext) {
|
||||
int j, i = (int) strlen(s);
|
||||
|
||||
if (i > MAXLINE - 5)
|
||||
return (-1);
|
||||
|
||||
for(j=i-1;j>=0;j--)
|
||||
{
|
||||
if(s[j]==DIRCHAR)
|
||||
{
|
||||
for (j = i - 1; j >= 0; j--) {
|
||||
if (s[j] == DIRCHAR) {
|
||||
strcpy(s + i, ext);
|
||||
break;
|
||||
}
|
||||
if(s[j]=='.')
|
||||
{
|
||||
if (s[j] == '.') {
|
||||
strcpy(s + j, ext);
|
||||
break;
|
||||
}
|
||||
|
@ -675,18 +721,14 @@ static int setfext(char *s, char *ext)
|
|||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static long ga_p1(void)
|
||||
{
|
||||
static long ga_p1(void) {
|
||||
return (afile->mn.tmpz);
|
||||
}
|
||||
static long gm_p1(void)
|
||||
{
|
||||
static long gm_p1(void) {
|
||||
return (TMPMEM);
|
||||
}
|
||||
|
||||
static int pass2(void)
|
||||
{
|
||||
static int pass2(void) {
|
||||
int c, er, l, ll, i, al;
|
||||
Datei datei;
|
||||
signed char *dataseg = NULL;
|
||||
|
@ -704,8 +746,7 @@ static int pass2(void)
|
|||
filep = &datei;
|
||||
afile->mn.tmpe = 0L;
|
||||
|
||||
while((ner_max==0 || ner<ner_max) && afile->mn.tmpe<afile->mn.tmpz)
|
||||
{
|
||||
while ((ner_max == 0 || ner < ner_max) && afile->mn.tmpe < afile->mn.tmpz) {
|
||||
// get the length of the entry (now two byte - need to handle the sign)
|
||||
l = 255 & afile->mn.tmp[afile->mn.tmpe++];
|
||||
l |= afile->mn.tmp[afile->mn.tmpe++] << 8;
|
||||
|
@ -713,37 +754,32 @@ static int pass2(void)
|
|||
|
||||
//printf("%p: l=%d first=%02x\n", afile->mn.tmp+afile->mn.tmpe-1, l, 0xff & afile->mn.tmp[afile->mn.tmpe]);
|
||||
|
||||
if(!l)
|
||||
{
|
||||
if(afile->mn.tmp[afile->mn.tmpe]==T_LINE)
|
||||
{
|
||||
datei.fline=(afile->mn.tmp[afile->mn.tmpe+1]&255)+(afile->mn.tmp[afile->mn.tmpe+2]<<8);
|
||||
if (!l) {
|
||||
if (afile->mn.tmp[afile->mn.tmpe] == T_LINE) {
|
||||
datei.fline = (afile->mn.tmp[afile->mn.tmpe + 1] & 255)
|
||||
+ (afile->mn.tmp[afile->mn.tmpe + 2] << 8);
|
||||
afile->mn.tmpe += 3;
|
||||
list_line(datei.fline); /* set line number of next listing output */
|
||||
} else
|
||||
if(afile->mn.tmp[afile->mn.tmpe]==T_FILE)
|
||||
{
|
||||
} else if (afile->mn.tmp[afile->mn.tmpe] == T_FILE) {
|
||||
// copy the current line number from the current file descriptor
|
||||
datei.fline=(afile->mn.tmp[afile->mn.tmpe+1]&255)+(afile->mn.tmp[afile->mn.tmpe+2]<<8);
|
||||
datei.fline = (afile->mn.tmp[afile->mn.tmpe + 1] & 255)
|
||||
+ (afile->mn.tmp[afile->mn.tmpe + 2] << 8);
|
||||
// copy the pointer to the file name in the current file descriptor
|
||||
// Note: the filename in the current file descriptor is separately malloc'd and
|
||||
// thus save to store the pointer
|
||||
memcpy(&datei.fname, afile->mn.tmp+afile->mn.tmpe+3, sizeof(datei.fname));
|
||||
memcpy(&datei.fname, afile->mn.tmp + afile->mn.tmpe + 3,
|
||||
sizeof(datei.fname));
|
||||
afile->mn.tmpe += 3 + sizeof(datei.fname);
|
||||
|
||||
list_filename(datei.fname); /* set file name of next listing output */
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
/* do not attempt address mode optimization on pass 2 */
|
||||
|
||||
/* t_p2_l() includes the listing call to do_listing() */
|
||||
er = t_p2_l(afile->mn.tmp + afile->mn.tmpe, &ll, &al);
|
||||
if(er==E_NOLINE)
|
||||
{
|
||||
} else
|
||||
if(er==E_OK)
|
||||
{
|
||||
if (er == E_NOLINE) {
|
||||
} else if (er == E_OK) {
|
||||
if (segment < SEG_DATA) {
|
||||
for (i = 0; i < ll; i++)
|
||||
chrput(afile->mn.tmp[afile->mn.tmpe + i]);
|
||||
|
@ -751,9 +787,7 @@ static int pass2(void)
|
|||
memcpy(datap, afile->mn.tmp + afile->mn.tmpe, ll);
|
||||
datap += ll;
|
||||
}
|
||||
} else
|
||||
if(er==E_DSB)
|
||||
{
|
||||
} else if (er == E_DSB) {
|
||||
c = afile->mn.tmp[afile->mn.tmpe];
|
||||
if (segment < SEG_DATA) {
|
||||
/*printf("E_DSB, ll=%d, l=%d, c=%c\n",ll,l,afile->mn.tmp[afile->mn.tmpe]);*/
|
||||
|
@ -780,15 +814,14 @@ fprintf(stderr, "%i: %02x\n", i, afile->mn.tmp[afile->mn.tmpe+i]);
|
|||
}
|
||||
*/
|
||||
|
||||
offset = afile->mn.tmp[i] +
|
||||
(afile->mn.tmp[i+1] << 8) +
|
||||
(afile->mn.tmp[i+2] << 16);
|
||||
fstart = afile->mn.tmp[i+3] + 1 +
|
||||
(afile->mn.tmp[i+4] << 8);
|
||||
offset = afile->mn.tmp[i] + (afile->mn.tmp[i + 1] << 8)
|
||||
+ (afile->mn.tmp[i + 2] << 16);
|
||||
fstart = afile->mn.tmp[i + 3] + 1 + (afile->mn.tmp[i + 4] << 8);
|
||||
/* usually redundant but here for single-char names
|
||||
that get interpreted as chars */
|
||||
flen = afile->mn.tmp[i + 5];
|
||||
if (flen > 1) fstart++;
|
||||
if (flen > 1)
|
||||
fstart++;
|
||||
/* now fstart points either to string past quote and
|
||||
length mark, OR, single char byte */
|
||||
/*
|
||||
|
@ -833,16 +866,15 @@ fprintf(stderr, "offset = %i length = %i fstart = %i flen = %i charo = %c\n",
|
|||
}
|
||||
if (relmode) {
|
||||
if ((ll = fwrite(dataseg, 1, dlen, fpout)) < dlen) {
|
||||
fprintf(stderr, "Problems writing %d bytes, return gives %d\n",dlen,ll);
|
||||
fprintf(stderr, "Problems writing %d bytes, return gives %d\n",
|
||||
dlen, ll);
|
||||
}
|
||||
}
|
||||
|
||||
return (ner);
|
||||
}
|
||||
|
||||
|
||||
static int pass1(void)
|
||||
{
|
||||
static int pass1(void) {
|
||||
signed char o[2 * MAXLINE]; /* doubled for token listing */
|
||||
int l, er, al;
|
||||
|
||||
|
@ -852,38 +884,39 @@ static int pass1(void)
|
|||
ner = 0;
|
||||
|
||||
/*FIXIT*/
|
||||
while(!(er=xa_getline(s)))
|
||||
{
|
||||
while (!(er = xa_getline(s))) {
|
||||
er = t_p1((signed char*) s, o, &l, &al);
|
||||
switch (segment) {
|
||||
case SEG_ABS:
|
||||
case SEG_TEXT: tlen += al; break;
|
||||
case SEG_DATA: dlen += al; break;
|
||||
case SEG_BSS : blen += al; break;
|
||||
case SEG_ZERO: zlen += al; break;
|
||||
case SEG_TEXT:
|
||||
tlen += al;
|
||||
break;
|
||||
case SEG_DATA:
|
||||
dlen += al;
|
||||
break;
|
||||
case SEG_BSS:
|
||||
blen += al;
|
||||
break;
|
||||
case SEG_ZERO:
|
||||
zlen += al;
|
||||
break;
|
||||
}
|
||||
|
||||
//printf(": er= %d, l=%d\n",er,l);
|
||||
|
||||
if(l)
|
||||
{
|
||||
if(er)
|
||||
{
|
||||
if(er==E_OKDEF)
|
||||
{
|
||||
if (l) {
|
||||
if (er) {
|
||||
if (er == E_OKDEF) {
|
||||
if (!(er = puttmpw(l)))
|
||||
er = puttmps(o, l);
|
||||
} else
|
||||
if(er==E_NOLINE)
|
||||
} else if (er == E_NOLINE)
|
||||
er = E_OK;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
if (!(er = puttmpw(-l)))
|
||||
er = puttmps(o, l);
|
||||
}
|
||||
}
|
||||
if(er)
|
||||
{
|
||||
if (er) {
|
||||
lineout();
|
||||
errout(er);
|
||||
}
|
||||
|
@ -896,8 +929,6 @@ static int pass1(void)
|
|||
errout(er);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* { int i; printf("Pass 1 \n");
|
||||
for(i=0;i<afile->mn.tmpz;i++)
|
||||
fprintf(stderr, " %02x",255 & afile->mn.tmp[i]);
|
||||
|
@ -1048,8 +1079,7 @@ static char *ertxt[] = {
|
|||
static int gl;
|
||||
static int gf;
|
||||
|
||||
static int x_init(void)
|
||||
{
|
||||
static int x_init(void) {
|
||||
return 0;
|
||||
#if 0
|
||||
int er=0;
|
||||
|
@ -1061,28 +1091,24 @@ static int x_init(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static int puttmp(int c)
|
||||
{
|
||||
static int puttmp(int c) {
|
||||
int er = E_NOMEM;
|
||||
|
||||
//printf("puttmp: %02x -> %p \n",0xff & c, afile->mn.tmp+afile->mn.tmpz);
|
||||
|
||||
if(afile->mn.tmpz<TMPMEM)
|
||||
{
|
||||
if (afile->mn.tmpz < TMPMEM) {
|
||||
afile->mn.tmp[afile->mn.tmpz++] = c;
|
||||
er = E_OK;
|
||||
}
|
||||
return (er);
|
||||
}
|
||||
|
||||
static int puttmpw(int c)
|
||||
{
|
||||
static int puttmpw(int c) {
|
||||
int er = E_NOMEM;
|
||||
|
||||
//printf("puttmp: %02x -> %p \n",0xff & c, afile->mn.tmp+afile->mn.tmpz);
|
||||
|
||||
if(afile->mn.tmpz<TMPMEM-1)
|
||||
{
|
||||
if (afile->mn.tmpz < TMPMEM - 1) {
|
||||
afile->mn.tmp[afile->mn.tmpz++] = c & 0xff;
|
||||
afile->mn.tmp[afile->mn.tmpz++] = (c >> 8) & 0xff;
|
||||
er = E_OK;
|
||||
|
@ -1090,14 +1116,12 @@ static int puttmpw(int c)
|
|||
return (er);
|
||||
}
|
||||
|
||||
static int puttmps(signed char *s, int l)
|
||||
{
|
||||
static int puttmps(signed char *s, int l) {
|
||||
int i = 0, er = E_NOMEM;
|
||||
|
||||
// printf("puttmps %d bytes from %p to %p:", l, s, afile->mn.tmp+afile->mn.tmpz);
|
||||
|
||||
if(afile->mn.tmpz+l<TMPMEM)
|
||||
{
|
||||
if (afile->mn.tmpz + l < TMPMEM) {
|
||||
while (i < l) {
|
||||
//printf(" %02x", 0xff & s[i]);
|
||||
afile->mn.tmp[afile->mn.tmpz++] = s[i++];
|
||||
|
@ -1111,8 +1135,7 @@ static int puttmps(signed char *s, int l)
|
|||
|
||||
static char l[MAXLINE];
|
||||
|
||||
static int xa_getline(char *s)
|
||||
{
|
||||
static int xa_getline(char *s) {
|
||||
static int ec;
|
||||
|
||||
static int i, c;
|
||||
|
@ -1121,10 +1144,8 @@ static int xa_getline(char *s)
|
|||
j = hkfl = comcom = 0;
|
||||
ec = E_OK;
|
||||
|
||||
if(!gl)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (!gl) {
|
||||
do {
|
||||
ec = pgetline(l);
|
||||
i = 0;
|
||||
while (l[i] == ' ')
|
||||
|
@ -1133,17 +1154,13 @@ static int xa_getline(char *s)
|
|||
i++;
|
||||
gf = 1;
|
||||
|
||||
if(ec==E_NEWLINE)
|
||||
{
|
||||
if (ec == E_NEWLINE) {
|
||||
puttmpw(0);
|
||||
puttmp(T_LINE);
|
||||
puttmpw(filep->fline);
|
||||
ec = E_OK;
|
||||
|
||||
}
|
||||
else
|
||||
if(ec==E_NEWFILE)
|
||||
{
|
||||
} else if (ec == E_NEWFILE) {
|
||||
puttmpw(0);
|
||||
puttmp(T_FILE);
|
||||
puttmpw(filep->fline);
|
||||
|
@ -1154,8 +1171,7 @@ static int xa_getline(char *s)
|
|||
}
|
||||
|
||||
gl = 0;
|
||||
if(!ec || ec==E_EOF)
|
||||
{
|
||||
if (!ec || ec == E_EOF) {
|
||||
int startofline = 1;
|
||||
do {
|
||||
c = s[j] = l[i++];
|
||||
|
@ -1175,10 +1191,10 @@ static int xa_getline(char *s)
|
|||
/* if the next char is a "=" - so that we have a ":=" - and we
|
||||
we have ca65 compatibility, we ignore the colon */
|
||||
// also check for ":+" and ":-"
|
||||
|
||||
//#error gotta get collab into this test
|
||||
//if (((!startofline) && l[i]!='=' && l[i]!='+' && l[i]!='-') || !ca65 || comcom) {
|
||||
if (((!startofline) && l[i]!='=' && l[i]!='+' && l[i]!='-') || !(ca65 || collab) || comcom) {
|
||||
if (((!startofline) && l[i] != '=' && l[i] != '+' && l[i] != '-')
|
||||
|| !(ca65 || collab) || comcom) {
|
||||
/* but otherwise we check if it is in a comment and we have
|
||||
MASM or CA65 compatibility, then we ignore the colon as well */
|
||||
if (!comcom || !(masm || ca65 || collab)) {
|
||||
|
@ -1209,26 +1225,23 @@ void set_align(int a) {
|
|||
align = (a > align) ? a : align;
|
||||
}
|
||||
|
||||
static void lineout(void)
|
||||
{
|
||||
if(gf)
|
||||
{
|
||||
static void lineout(void) {
|
||||
if (gf) {
|
||||
logout(filep->flinep);
|
||||
logout("\n");
|
||||
gf = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void errout(int er)
|
||||
{
|
||||
void errout(int er) {
|
||||
if (er <= -ANZERR || er > -1) {
|
||||
if (er >= -(ANZERR + ANZWARN) && er <= -ANZERR) {
|
||||
sprintf(out,"%s:line %d: %04x: Warning - %s\n",
|
||||
filep->fname, filep->fline, pc[segment], ertxt[(-er)-1]);
|
||||
sprintf(out, "%s:line %d: %04x: Warning - %s\n", filep->fname,
|
||||
filep->fline, pc[segment], ertxt[(-er) - 1]);
|
||||
} else {
|
||||
/* sprintf(out,"%s:Zeile %d: %04x:Unbekannter Fehler Nr.: %d\n",*/
|
||||
sprintf(out,"%s:line %d: %04x: Unknown error # %d\n",
|
||||
filep->fname,filep->fline,pc[segment],er);
|
||||
sprintf(out, "%s:line %d: %04x: Unknown error # %d\n", filep->fname,
|
||||
filep->fline, pc[segment], er);
|
||||
ner++;
|
||||
}
|
||||
} else {
|
||||
|
@ -1236,23 +1249,21 @@ void errout(int er)
|
|||
sprintf(out, "%s:line %d: %04x:Label '%s' not defined\n",
|
||||
filep->fname, filep->fline, pc[segment], lz);
|
||||
else
|
||||
sprintf(out,"%s:line %d: %04x:%s error\n",
|
||||
filep->fname,filep->fline,pc[segment],ertxt[(-er)-1]);
|
||||
sprintf(out, "%s:line %d: %04x:%s error\n", filep->fname,
|
||||
filep->fline, pc[segment], ertxt[(-er) - 1]);
|
||||
|
||||
ner++;
|
||||
}
|
||||
logout(out);
|
||||
}
|
||||
|
||||
static void chrput(int c)
|
||||
{
|
||||
static void chrput(int c) {
|
||||
/* printf(" %02x",c&255);*/
|
||||
|
||||
putc(c & 0x00ff, fpout);
|
||||
}
|
||||
|
||||
void logout(char *s)
|
||||
{
|
||||
void logout(char *s) {
|
||||
fprintf(stderr, "%s", s);
|
||||
if (fperr)
|
||||
fprintf(fperr, "%s", s);
|
||||
|
@ -1265,13 +1276,8 @@ typedef struct {
|
|||
int *flag;
|
||||
} compat_set;
|
||||
|
||||
static compat_set compat_sets[] = {
|
||||
{ "MASM", &masm },
|
||||
{ "CA65", &ca65 },
|
||||
{ "C", &ctypes },
|
||||
{ "XA23", &xa23 },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
static compat_set compat_sets[] = { { "MASM", &masm }, { "CA65", &ca65 }, { "C",
|
||||
&ctypes }, { "XA23", &xa23 }, { NULL, NULL } };
|
||||
|
||||
int set_compat(char *compat_name) {
|
||||
int i = 0;
|
||||
|
@ -1281,8 +1287,8 @@ int set_compat(char *compat_name) {
|
|||
(*compat_sets[i].flag) = 1;
|
||||
|
||||
/* warn on old versions of xa */
|
||||
if (xa23) fprintf(stderr,
|
||||
"Warning: -XXA23 is explicitly deprecated\n");
|
||||
if (xa23)
|
||||
fprintf(stderr, "Warning: -XXA23 is explicitly deprecated\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1291,4 +1297,3 @@ int set_compat(char *compat_name) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
90
xa/src/xaa.c
90
xa/src/xaa.c
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* Preprocessing arithmetic module
|
||||
*
|
||||
|
@ -30,7 +30,8 @@
|
|||
#include "xaa.h"
|
||||
#include "xat.h"
|
||||
|
||||
static int pr[]= { P_START,P_ADD,P_ADD,P_MULT,P_MULT,P_SHIFT,P_SHIFT,P_CMP,
|
||||
static int pr[] = { P_START, P_ADD, P_ADD, P_MULT, P_MULT, P_SHIFT, P_SHIFT,
|
||||
P_CMP,
|
||||
P_CMP, P_EQU, P_CMP, P_CMP, P_EQU, P_AND, P_XOR, P_OR,
|
||||
P_LAND, P_LOR, P_EQU, P_START };
|
||||
|
||||
|
@ -42,8 +43,7 @@ static int get_op(signed char*,int*);
|
|||
static int do_op(int*, int, int);
|
||||
|
||||
/* s = string, v = variable */
|
||||
int a_term(signed char *s, int *v, int *l, int xpc, int *pfl, int *label, int f)
|
||||
{
|
||||
int a_term(signed char *s, int *v, int *l, int xpc, int *pfl, int *label, int f) {
|
||||
int er = E_OK;
|
||||
int afl = 0, bfl;
|
||||
|
||||
|
@ -53,8 +53,7 @@ int a_term(signed char *s, int *v, int *l, int xpc, int *pfl, int *label, int f)
|
|||
pp = 0;
|
||||
pcc = xpc;
|
||||
|
||||
if(s[0]=='<')
|
||||
{
|
||||
if (s[0] == '<') {
|
||||
pp++;
|
||||
er = ag_term(s, P_START, v, &afl, label);
|
||||
bfl = afl & (A_MASK >> 8);
|
||||
|
@ -62,11 +61,10 @@ int a_term(signed char *s, int *v, int *l, int xpc, int *pfl, int *label, int f)
|
|||
/*fprintf(stderr,"low byte relocation for a high byte - won't work!\n");*/
|
||||
errout(W_LOWACC);
|
||||
}
|
||||
if(afl) *pfl=A_LOW | ((afl<<8) & A_FMASK);
|
||||
if (afl)
|
||||
*pfl = A_LOW | ((afl << 8) & A_FMASK);
|
||||
*v = *v & 255;
|
||||
} else
|
||||
if(s[pp]=='>')
|
||||
{
|
||||
} else if (s[pp] == '>') {
|
||||
pp++;
|
||||
er = ag_term(s, P_START, v, &afl, label);
|
||||
bfl = afl & (A_MASK >> 8);
|
||||
|
@ -74,18 +72,18 @@ int a_term(signed char *s, int *v, int *l, int xpc, int *pfl, int *label, int f)
|
|||
/*fprintf(stderr,"high byte relocation for a low byte - won't work!\n");*/
|
||||
errout(W_HIGHACC);
|
||||
}
|
||||
if(afl) *pfl=A_HIGH | ((afl<<8) & A_FMASK) | (*v & 255);
|
||||
if (afl)
|
||||
*pfl = A_HIGH | ((afl << 8) & A_FMASK) | (*v & 255);
|
||||
*v = (*v >> 8) & 255;
|
||||
}
|
||||
else
|
||||
if(s[pp]!=T_END) {
|
||||
} else if (s[pp] != T_END) {
|
||||
er = ag_term(s, P_START, v, &afl, label);
|
||||
bfl = afl & (A_MASK >> 8);
|
||||
if (bfl && (bfl != (A_ADR >> 8))) {
|
||||
/*fprintf(stderr,"address relocation for a low or high byte - won't work!\n");*/
|
||||
errout(W_ADDRACC);
|
||||
}
|
||||
if(afl) *pfl = A_ADR | ((afl<<8) & A_FMASK);
|
||||
if (afl)
|
||||
*pfl = A_ADR | ((afl << 8) & A_FMASK);
|
||||
} else {
|
||||
er = E_SYNTAX;
|
||||
}
|
||||
|
@ -95,16 +93,14 @@ int a_term(signed char *s, int *v, int *l, int xpc, int *pfl, int *label, int f)
|
|||
return (er);
|
||||
}
|
||||
|
||||
static int ag_term(signed char *s, int p, int *v, int *nafl, int *label)
|
||||
{
|
||||
static int ag_term(signed char *s, int p, int *v, int *nafl, int *label) {
|
||||
int er = E_OK, o, w, mf = 1, afl;
|
||||
|
||||
afl = 0;
|
||||
|
||||
//fprintf(stderr, "ag_term(%02x %02x %02x %02x %02x %02x\n",s[0],s[1],s[2],s[3],s[4],s[5]);
|
||||
|
||||
while(s[pp]=='-')
|
||||
{
|
||||
while (s[pp] == '-') {
|
||||
pp++;
|
||||
mf = -mf;
|
||||
}
|
||||
|
@ -123,19 +119,15 @@ static int ag_term(signed char *s, int p, int *v, int *nafl, int *label)
|
|||
*v = !(*v);
|
||||
} else
|
||||
#endif
|
||||
if(s[pp]=='(')
|
||||
{
|
||||
if (s[pp] == '(') {
|
||||
pp++;
|
||||
if(!(er=ag_term(s,P_START,v,&afl,label)))
|
||||
{
|
||||
if (!(er = ag_term(s, P_START, v, &afl, label))) {
|
||||
if (s[pp] != ')')
|
||||
er = E_SYNTAX;
|
||||
else
|
||||
pp++;
|
||||
}
|
||||
} else
|
||||
if(s[pp]==T_LABEL)
|
||||
{
|
||||
} else if (s[pp] == T_LABEL) {
|
||||
er = l_get(cval(s + pp + 1), v, &afl);
|
||||
|
||||
/*
|
||||
|
@ -153,10 +145,7 @@ static int ag_term(signed char *s, int p, int *v, int *nafl, int *label)
|
|||
}
|
||||
}
|
||||
pp += 3;
|
||||
}
|
||||
else
|
||||
if(s[pp]==T_VALUE || s[pp] == T_CAST)
|
||||
{
|
||||
} else if (s[pp] == T_VALUE || s[pp] == T_CAST) {
|
||||
while (s[pp] == T_CAST) {
|
||||
pp += 2;
|
||||
}
|
||||
|
@ -165,48 +154,38 @@ static int ag_term(signed char *s, int p, int *v, int *nafl, int *label)
|
|||
/*
|
||||
printf("value: v=%04x\n",*v);
|
||||
*/
|
||||
}
|
||||
else
|
||||
if(s[pp]==T_POINTER)
|
||||
{
|
||||
} else if (s[pp] == T_POINTER) {
|
||||
afl = s[pp + 1];
|
||||
*v = cval(s + pp + 2);
|
||||
pp += 6;
|
||||
/*
|
||||
printf("pointer: v=%04x, afl=%04x\n",*v,afl);
|
||||
*/
|
||||
}
|
||||
else
|
||||
if(s[pp]=='*')
|
||||
{
|
||||
} else if (s[pp] == '*') {
|
||||
*v = pcc;
|
||||
pp++;
|
||||
afl = segment;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
er = E_SYNTAX;
|
||||
}
|
||||
|
||||
*v *= mf;
|
||||
|
||||
while(!er && s[pp]!=')' && s[pp]!=']' && s[pp]!=',' && s[pp]!=T_END && s[pp]!=T_COMMENT)
|
||||
{
|
||||
while (!er && s[pp] != ')' && s[pp] != ']' && s[pp] != ',' && s[pp] != T_END
|
||||
&& s[pp] != T_COMMENT) {
|
||||
//fprintf(stderr, "ag_term while: s[pp=%d]=%02x\n", pp, s[pp]);
|
||||
er = get_op(s, &o);
|
||||
|
||||
if(!er && pr[o]>p)
|
||||
{
|
||||
if (!er && pr[o] > p) {
|
||||
pp += 1;
|
||||
if(!(er=ag_term(s,pr[o],&w, nafl, label)))
|
||||
{
|
||||
if (!(er = ag_term(s, pr[o], &w, nafl, label))) {
|
||||
if (afl || *nafl) { /* check pointer arithmetic */
|
||||
if((afl == *nafl) && (afl!=SEG_UNDEFZP) && (afl!=SEG_UNDEF) && o==2) {
|
||||
if ((afl == *nafl) && (afl != SEG_UNDEFZP)
|
||||
&& (afl != SEG_UNDEF) && o == 2) {
|
||||
afl = 0; /* subtract two pointers */
|
||||
} else
|
||||
if(((afl && !*nafl) || (*nafl && !afl)) && o==1) {
|
||||
} else if (((afl && !*nafl) || (*nafl && !afl)) && o == 1) {
|
||||
afl = (afl | *nafl); /* add constant to pointer */
|
||||
} else
|
||||
if((afl && !*nafl) && o==2) {
|
||||
} else if ((afl && !*nafl) && o == 2) {
|
||||
afl = (afl | *nafl); /* subtract constant from pointer */
|
||||
} else {
|
||||
if ((!afl && *nafl) && o == 2) {
|
||||
|
@ -224,7 +203,8 @@ printf("pointer: v=%04x, afl=%04x\n",*v,afl);
|
|||
afl = 0;
|
||||
}
|
||||
}
|
||||
if(!er) er=do_op(v,w,o);
|
||||
if (!er)
|
||||
er = do_op(v, w, o);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
|
@ -234,8 +214,7 @@ printf("pointer: v=%04x, afl=%04x\n",*v,afl);
|
|||
return (er);
|
||||
}
|
||||
|
||||
static int get_op(signed char *s, int *o)
|
||||
{
|
||||
static int get_op(signed char *s, int *o) {
|
||||
int er;
|
||||
|
||||
*o = s[pp];
|
||||
|
@ -256,8 +235,7 @@ static int get_op(signed char *s, int *o)
|
|||
return (er);
|
||||
}
|
||||
|
||||
static int do_op(int *w,int w2,int o)
|
||||
{
|
||||
static int do_op(int *w, int w2, int o) {
|
||||
int er = E_OK;
|
||||
switch (o) {
|
||||
case 1:
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -122,4 +121,3 @@ signed char convert_char(signed char c) {
|
|||
return convert_func(c);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Maintained by Cameron Kaiser
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -38,10 +38,7 @@
|
|||
#define TMPMEM 2000000L /* temporary memory buffer from Pass1 to Pass 2 (includes all source, thus enlarged) */
|
||||
|
||||
typedef enum {
|
||||
STD = 0,
|
||||
CHEAP = 1,
|
||||
UNNAMED = 2,
|
||||
UNNAMED_DEF = 3
|
||||
STD = 0, CHEAP = 1, UNNAMED = 2, UNNAMED_DEF = 3
|
||||
} xalabel_t;
|
||||
|
||||
typedef struct LabOcc {
|
||||
|
@ -83,7 +80,6 @@ typedef struct {
|
|||
int nextindex;
|
||||
} List;
|
||||
|
||||
|
||||
#define MEMLEN (4 + TMPMEM + MAXPP + LABMEM + \
|
||||
(long)(sizeof (Labtab) * ANZLAB) + \
|
||||
(long)(sizeof (List) * ANZDEF))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
221
xa/src/xal.c
221
xa/src/xal.c
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* Label management module (also see xau.c)
|
||||
*
|
||||
|
@ -58,45 +58,37 @@ static int cll_get();
|
|||
static void cll_clear();
|
||||
static int cll_getcur();
|
||||
|
||||
|
||||
static Labtab *ltp;
|
||||
|
||||
int l_init(void)
|
||||
{
|
||||
int l_init(void) {
|
||||
cll_init();
|
||||
//unn_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ga_lab(void)
|
||||
{
|
||||
int ga_lab(void) {
|
||||
return (afile->la.lti);
|
||||
}
|
||||
|
||||
int gm_lab(void)
|
||||
{
|
||||
int gm_lab(void) {
|
||||
return (ANZLAB);
|
||||
}
|
||||
|
||||
long gm_labm(void)
|
||||
{
|
||||
long gm_labm(void) {
|
||||
return ((long) LABMEM);
|
||||
}
|
||||
|
||||
long ga_labm(void)
|
||||
{
|
||||
long ga_labm(void) {
|
||||
return (0 /*lni*/);
|
||||
}
|
||||
|
||||
void printllist(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
FILE *fp; {
|
||||
int i;
|
||||
LabOcc *p;
|
||||
char *fname = NULL;
|
||||
|
||||
for(i=0;i<afile->la.lti;i++)
|
||||
{
|
||||
for (i = 0; i < afile->la.lti; i++) {
|
||||
ltp = afile->la.lt + i;
|
||||
fprintf(fp, "%s, 0x%04x, %d, 0x%04x\n", ltp->n, ltp->val, ltp->blk,
|
||||
ltp->afl);
|
||||
|
@ -104,7 +96,8 @@ FILE *fp;
|
|||
if (p) {
|
||||
while (p) {
|
||||
if (fname != p->fname) {
|
||||
if(p!=ltp->occlist) fprintf(fp,"\n");
|
||||
if (p != ltp->occlist)
|
||||
fprintf(fp, "\n");
|
||||
fprintf(fp, " %s", p->fname);
|
||||
fname = p->fname;
|
||||
}
|
||||
|
@ -207,7 +200,6 @@ int lg_toglobal(char *s ) {
|
|||
return er;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* define a global zeropage label (from the .importzp pseudo opcode))
|
||||
* "s" is a pointer to the first label character, end is at \0
|
||||
|
@ -225,8 +217,7 @@ int lg_importzp(int n) {
|
|||
|
||||
/**********************************************************************************/
|
||||
|
||||
int l_def(char *s, int *l, int *x, int *f)
|
||||
{
|
||||
int l_def(char *s, int *l, int *x, int *f) {
|
||||
int n, er, b, i = 0;
|
||||
xalabel_t cll_fl;
|
||||
|
||||
|
@ -242,28 +233,22 @@ int l_def(char *s, int *l, int *x, int *f)
|
|||
//n++; /* block number b is absolute */
|
||||
//b=unn_get(); /* current (possibly newly allocated) unnamed label block */
|
||||
cll_fl = UNNAMED; // keep the cheap local label block
|
||||
} else
|
||||
if(s[0]=='-')
|
||||
{
|
||||
} else if (s[0] == '-') {
|
||||
*f += 1; /* label is being redefined */
|
||||
i++;
|
||||
} else
|
||||
if(s[0]=='@')
|
||||
{
|
||||
} else if (s[0] == '@') {
|
||||
i++;
|
||||
n++; /* block number b is absolute */
|
||||
b = cll_get(); /* current (possibly newly allocated) cheap label block */
|
||||
cll_fl = CHEAP; /* do not clear the cll block again... */
|
||||
} else
|
||||
if(s[0]=='+')
|
||||
{
|
||||
} else if (s[0] == '+') {
|
||||
i++;
|
||||
n++; /* block number b is absolute */
|
||||
b = 0; /* global block number */
|
||||
}
|
||||
while(s[i]=='&')
|
||||
{
|
||||
if (n) b=0; /* reset block number */
|
||||
while (s[i] == '&') {
|
||||
if (n)
|
||||
b = 0; /* reset block number */
|
||||
n = 0; /* block number is relative */
|
||||
i++;
|
||||
b++; /* one (more) level up the block stack */
|
||||
|
@ -278,29 +263,25 @@ int l_def(char *s, int *l, int *x, int *f)
|
|||
cll_clear();
|
||||
}
|
||||
|
||||
if((!isalpha(s[i])) && (s[i]!='_') && !((ca65 || collab) && ((cll_fl == UNNAMED) || isdigit(s[i])) ) ) {
|
||||
if ((!isalpha(s[i])) && (s[i] != '_')
|
||||
&& !((ca65 || collab) && ((cll_fl == UNNAMED) || isdigit(s[i])))) {
|
||||
//printf("SYNTAX ca65=%d collab=%d cll_fl=%d, i=%d, s[i]=%02x (%c)\n", ca65, collab, cll_fl, i, s[i], s[i]);
|
||||
er = E_SYNTAX;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
er = E_NODEF;
|
||||
if (cll_fl != UNNAMED) {
|
||||
er = ll_search(s + i, &n, cll_fl);
|
||||
}
|
||||
|
||||
if(er==E_OK)
|
||||
{
|
||||
if (er == E_OK) {
|
||||
//printf("l_def OK: cll_fl=%d, i=%d, s=%s\n", cll_fl, i, s);
|
||||
/* we actually found an existing label in the same scope */
|
||||
ltp = afile->la.lt + n;
|
||||
|
||||
if(*f)
|
||||
{
|
||||
if (*f) {
|
||||
/* redefinition of label */
|
||||
*l = ltp->len + i;
|
||||
} else
|
||||
if(ltp->fl == 0)
|
||||
{
|
||||
} else if (ltp->fl == 0) {
|
||||
/* label has not been defined yet, (e.g. pass1 forward ref), so we try to set it. */
|
||||
*l = ltp->len + i;
|
||||
if (b_ltest(ltp->blk, b))
|
||||
|
@ -308,9 +289,7 @@ int l_def(char *s, int *l, int *x, int *f)
|
|||
else
|
||||
ltp->blk = b;
|
||||
|
||||
} else
|
||||
if(ltp->fl == 3)
|
||||
{
|
||||
} else if (ltp->fl == 3) {
|
||||
/* label has been defined as -U undef'd label so far - we need to check */
|
||||
*l = ltp->len + i;
|
||||
if (b_ltest(ltp->origblk, b))
|
||||
|
@ -320,9 +299,7 @@ int l_def(char *s, int *l, int *x, int *f)
|
|||
|
||||
} else
|
||||
er = E_LABDEF;
|
||||
} else
|
||||
if(er==E_NODEF)
|
||||
{
|
||||
} else if (er == E_NODEF) {
|
||||
|
||||
if (!(er = ll_def(s + i, &n, b, cll_fl))) /* store the label in the table of labels */
|
||||
{
|
||||
|
@ -339,8 +316,7 @@ int l_def(char *s, int *l, int *x, int *f)
|
|||
return (er);
|
||||
}
|
||||
|
||||
int l_search(char *s, int *l, int *x, int *v, int *afl)
|
||||
{
|
||||
int l_search(char *s, int *l, int *x, int *v, int *afl) {
|
||||
int n, er, b;
|
||||
xalabel_t cll_fl;
|
||||
|
||||
|
@ -351,8 +327,7 @@ int l_search(char *s, int *l, int *x, int *v, int *afl)
|
|||
if (s[0] == '@') {
|
||||
cll_fl = CHEAP;
|
||||
s++;
|
||||
} else
|
||||
if (s[0]==':') {
|
||||
} else if (s[0] == ':') {
|
||||
cll_fl = UNNAMED_DEF;
|
||||
s++;
|
||||
}
|
||||
|
@ -363,27 +338,21 @@ int l_search(char *s, int *l, int *x, int *v, int *afl)
|
|||
}
|
||||
|
||||
//printf("l_search: lab=%s(afl=%d, er=%d, cll_fl=%d, cll_cur=%d)\n",s,*afl,er, cll_fl, cll_getcur());
|
||||
if(er==E_OK)
|
||||
{
|
||||
if (er == E_OK) {
|
||||
ltp = afile->la.lt + n;
|
||||
*l = ltp->len + ((cll_fl == STD) ? 0 : 1);
|
||||
if(ltp->fl == 1)
|
||||
{
|
||||
if (ltp->fl == 1) {
|
||||
l_get(n, v, afl);/* *v=lt[n].val;*/
|
||||
*x = n;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
er = E_NODEF;
|
||||
lz = ltp->n;
|
||||
*x = n;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (cll_fl == CHEAP) {
|
||||
b = cll_get();
|
||||
} else
|
||||
if(cll_fl == UNNAMED_DEF) {
|
||||
} else if (cll_fl == UNNAMED_DEF) {
|
||||
b_get(&b); // b=unn_get();
|
||||
} else {
|
||||
b_get(&b);
|
||||
|
@ -397,8 +366,7 @@ int l_search(char *s, int *l, int *x, int *v, int *afl)
|
|||
*l = ltp->len + ((cll_fl == STD) ? 0 : 1);
|
||||
//*l=ltp->len + cll_fl;
|
||||
|
||||
if(!er)
|
||||
{
|
||||
if (!er) {
|
||||
er = E_NODEF;
|
||||
lz = ltp->n;
|
||||
}
|
||||
|
@ -406,8 +374,7 @@ int l_search(char *s, int *l, int *x, int *v, int *afl)
|
|||
return (er);
|
||||
}
|
||||
|
||||
int l_vget(int n, int *v, char **s)
|
||||
{
|
||||
int l_vget(int n, int *v, char **s) {
|
||||
ltp = afile->la.lt + n;
|
||||
(*v) = ltp->val;
|
||||
*s = ltp->n;
|
||||
|
@ -423,7 +390,8 @@ void l_addocc(int n, int *v, int *afl) {
|
|||
pp = NULL;
|
||||
p = ltp->occlist;
|
||||
while (p) {
|
||||
if (p->line == filep->fline && p->fname == filep->fname) return;
|
||||
if (p->line == filep->fline && p->fname == filep->fname)
|
||||
return;
|
||||
pp = p;
|
||||
p = p->next;
|
||||
}
|
||||
|
@ -445,7 +413,8 @@ void l_addocc(int n, int *v, int *afl) {
|
|||
/* for the list functionality */
|
||||
char* l_get_name(int n, xalabel_t *is_cll) {
|
||||
if (n > afile->la.ltm) {
|
||||
fprintf(stderr, "Corrupted structures! n=%d, but max=%d\n", n, afile->la.ltm);
|
||||
fprintf(stderr, "Corrupted structures! n=%d, but max=%d\n", n,
|
||||
afile->la.ltm);
|
||||
exit(1);
|
||||
}
|
||||
ltp = afile->la.lt + n;
|
||||
|
@ -465,8 +434,7 @@ static int resolve_unnamed() {
|
|||
nextp = -1;
|
||||
if (c == '+') {
|
||||
nextp = ltp->blknext;
|
||||
} else
|
||||
if (c == '-') {
|
||||
} else if (c == '-') {
|
||||
nextp = ltp->blkprev;
|
||||
}
|
||||
//printf("::: nextp=%d\n", nextp);
|
||||
|
@ -488,16 +456,13 @@ char *l_get_unique_name(int n) {
|
|||
ltp = afile->la.lt + n;
|
||||
|
||||
if (ltp->is_cll == CHEAP || ltp->is_cll == STD) {
|
||||
sprintf(buf, "%d%c%s", ltp->blk,
|
||||
(ltp->is_cll == CHEAP) ? 'C' : '_',
|
||||
sprintf(buf, "%d%c%s", ltp->blk, (ltp->is_cll == CHEAP) ? 'C' : '_',
|
||||
ltp->n);
|
||||
} else
|
||||
if (ltp->is_cll == UNNAMED) {
|
||||
} else if (ltp->is_cll == UNNAMED) {
|
||||
// definition of unnamed label - name is NULL
|
||||
// so use the actual index
|
||||
sprintf(buf, "%dU%d", ltp->blk, n);
|
||||
} else
|
||||
if (ltp->is_cll == UNNAMED_DEF) {
|
||||
} else if (ltp->is_cll == UNNAMED_DEF) {
|
||||
// we actually need to find the correct label from the "+" and "-"
|
||||
// in the name
|
||||
int tmp = resolve_unnamed();
|
||||
|
@ -512,15 +477,16 @@ char *l_get_unique_name(int n) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
int l_get(int n, int *v, int *afl)
|
||||
{
|
||||
if(crossref) l_addocc(n,v,afl);
|
||||
int l_get(int n, int *v, int *afl) {
|
||||
if (crossref)
|
||||
l_addocc(n, v, afl);
|
||||
|
||||
ltp = afile->la.lt + n;
|
||||
|
||||
if (ltp->is_cll == UNNAMED_DEF) {
|
||||
int tmp = resolve_unnamed();
|
||||
if (tmp == -1) return E_NODEF;
|
||||
if (tmp == -1)
|
||||
return E_NODEF;
|
||||
// now ltp is set to the actual label
|
||||
}
|
||||
(*v) = ltp->val;
|
||||
|
@ -530,8 +496,7 @@ int l_get(int n, int *v, int *afl)
|
|||
return ((ltp->fl == 1) ? E_OK : E_NODEF);
|
||||
}
|
||||
|
||||
void l_set(int n, int v, int afl)
|
||||
{
|
||||
void l_set(int n, int v, int afl) {
|
||||
ltp = afile->la.lt + n;
|
||||
ltp->val = v;
|
||||
ltp->fl = 1;
|
||||
|
@ -540,11 +505,9 @@ void l_set(int n, int v, int afl)
|
|||
//printf("l_set('%s'(%d), v=$%04x, afl=%d\n",ltp->n, n, v, afl);
|
||||
}
|
||||
|
||||
static void ll_exblk(int a, int b)
|
||||
{
|
||||
static void ll_exblk(int a, int b) {
|
||||
int i;
|
||||
for (i=0;i<afile->la.lti;i++)
|
||||
{
|
||||
for (i = 0; i < afile->la.lti; i++) {
|
||||
ltp = afile->la.lt + i;
|
||||
if ((!ltp->fl) && (ltp->blk == a))
|
||||
ltp->blk = b;
|
||||
|
@ -552,8 +515,7 @@ static void ll_exblk(int a, int b)
|
|||
}
|
||||
|
||||
/* defines next label, returns new label number in out param n */
|
||||
static int ll_def(char *s, int *n, int b, xalabel_t ltype)
|
||||
{
|
||||
static int ll_def(char *s, int *n, int b, xalabel_t ltype) {
|
||||
int j = 0, er = E_NOMEM, hash;
|
||||
char *s2 = NULL;
|
||||
|
||||
|
@ -583,10 +545,12 @@ static int ll_def(char *s, int *n, int b, xalabel_t ltype)
|
|||
// alloc space and copy over name
|
||||
if (ltype == UNNAMED_DEF) {
|
||||
// unnamed lables are like ":--" or ":+" with variable length
|
||||
while((s[j]!='\0') && (s[j]=='+' || s[j]=='-')) j++;
|
||||
while ((s[j] != '\0') && (s[j] == '+' || s[j] == '-'))
|
||||
j++;
|
||||
} else {
|
||||
// standard (and cheap) labels are normal text
|
||||
while((s[j]!='\0') && (isalnum(s[j]) || (s[j]=='_'))) j++;
|
||||
while ((s[j] != '\0') && (isalnum(s[j]) || (s[j] == '_')))
|
||||
j++;
|
||||
}
|
||||
s2 = malloc(j + 1);
|
||||
if (!s2) {
|
||||
|
@ -638,35 +602,34 @@ int ll_search(char *s, int *n, xalabel_t cll_fl) /* search Label in Tab
|
|||
{
|
||||
int i, j = 0, k, er = E_NODEF, hash;
|
||||
|
||||
while(s[j] && (isalnum(s[j])||(s[j]=='_'))) j++;
|
||||
while (s[j] && (isalnum(s[j]) || (s[j] == '_')))
|
||||
j++;
|
||||
|
||||
hash = hashcode(s, j);
|
||||
i = afile->la.hashindex[hash];
|
||||
|
||||
if(i>=afile->la.ltm) return E_NODEF;
|
||||
if (i >= afile->la.ltm)
|
||||
return E_NODEF;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
ltp = afile->la.lt + i;
|
||||
|
||||
if(j==ltp->len)
|
||||
{
|
||||
for (k=0;(k<j)&&(ltp->n[k]==s[k]);k++);
|
||||
if (j == ltp->len) {
|
||||
for (k = 0; (k < j) && (ltp->n[k] == s[k]); k++)
|
||||
;
|
||||
|
||||
if ((j == k) && cll_fl == CHEAP) {
|
||||
if (ltp->blk == cll_getcur()) {
|
||||
er = E_OK;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
if (cll_fl == UNNAMED) {
|
||||
} else if (cll_fl == UNNAMED) {
|
||||
// TODO
|
||||
} else {
|
||||
//printf("ll_search:match labels %s with %p (%s) from block %d, block check is %d\n", s, ltp, ltp->n, ltp->blk, b_test(ltp->blk));
|
||||
/* check if the found label is in any of the blocks in the
|
||||
current block stack */
|
||||
if((j==k)&&(!b_test(ltp->blk)))
|
||||
{
|
||||
if ((j == k) && (!b_test(ltp->blk))) {
|
||||
/* ok, label found and it is reachable (its block nr is in the current block stack */
|
||||
er = E_OK;
|
||||
break;
|
||||
|
@ -694,12 +657,10 @@ int ll_search(char *s, int *n, xalabel_t cll_fl) /* search Label in Tab
|
|||
return (er);
|
||||
}
|
||||
|
||||
int ll_pdef(char *t)
|
||||
{
|
||||
int ll_pdef(char *t) {
|
||||
int n;
|
||||
|
||||
if(ll_search(t,&n, STD)==E_OK)
|
||||
{
|
||||
if (ll_search(t, &n, STD) == E_OK) {
|
||||
ltp = afile->la.lt + n;
|
||||
if (ltp->fl)
|
||||
return (E_OK);
|
||||
|
@ -710,8 +671,7 @@ int ll_pdef(char *t)
|
|||
/*
|
||||
* Write out the list of global labels in an o65 file
|
||||
*/
|
||||
int l_write(FILE *fp)
|
||||
{
|
||||
int l_write(FILE *fp) {
|
||||
int i, afl, n = 0;
|
||||
|
||||
if (noglob) {
|
||||
|
@ -730,8 +690,7 @@ int l_write(FILE *fp)
|
|||
fputc(n & 255, fp);
|
||||
fputc((n >> 8) & 255, fp);
|
||||
// iterate over labels and write out label
|
||||
for (i=0;i<afile->la.lti;i++)
|
||||
{
|
||||
for (i = 0; i < afile->la.lti; i++) {
|
||||
ltp = afile->la.lt + i;
|
||||
if ((!ltp->blk) && (ltp->fl == 1)) {
|
||||
// write global name
|
||||
|
@ -778,8 +737,7 @@ static int labind; /* last allocated label, -1 none yet alloc'd - used for linki
|
|||
static int bi; /* length of the block stack (minus 1, i.e. bi[bi] has the innermost block) */
|
||||
static int blk; /* current block number for allocation */
|
||||
|
||||
int b_init(void)
|
||||
{
|
||||
int b_init(void) {
|
||||
blk = 0;
|
||||
bi = 0;
|
||||
bt[bi] = blk;
|
||||
|
@ -788,30 +746,25 @@ int b_init(void)
|
|||
return (E_OK);
|
||||
}
|
||||
|
||||
int b_new(void)
|
||||
{
|
||||
int b_new(void) {
|
||||
return ++blk;
|
||||
}
|
||||
|
||||
int b_depth(void)
|
||||
{
|
||||
int b_depth(void) {
|
||||
return bi;
|
||||
}
|
||||
|
||||
int ga_blk(void)
|
||||
{
|
||||
int ga_blk(void) {
|
||||
return (blk);
|
||||
}
|
||||
|
||||
/**
|
||||
* open a new block scope
|
||||
*/
|
||||
int b_open(void)
|
||||
{
|
||||
int b_open(void) {
|
||||
int er = E_BLKOVR;
|
||||
|
||||
if(bi<MAXBLK-1)
|
||||
{
|
||||
if (bi < MAXBLK - 1) {
|
||||
bi++;
|
||||
bt[bi] = b_new();
|
||||
|
||||
|
@ -823,11 +776,9 @@ int b_open(void)
|
|||
/**
|
||||
* close a block scope
|
||||
*/
|
||||
int b_close(void)
|
||||
{
|
||||
int b_close(void) {
|
||||
|
||||
if(bi)
|
||||
{
|
||||
if (bi) {
|
||||
ll_exblk(bt[bi], bt[bi - 1]);
|
||||
bi--;
|
||||
} else {
|
||||
|
@ -841,8 +792,7 @@ int b_close(void)
|
|||
/**
|
||||
* get the block number of the current innermost block
|
||||
*/
|
||||
static int b_get(int *n)
|
||||
{
|
||||
static int b_get(int *n) {
|
||||
*n = bt[bi];
|
||||
|
||||
return (E_OK);
|
||||
|
@ -851,8 +801,7 @@ static int b_get(int *n)
|
|||
/**
|
||||
* returns the block number of the block "i" levels up in the current block stack
|
||||
*/
|
||||
static int b_fget(int *n, int i)
|
||||
{
|
||||
static int b_fget(int *n, int i) {
|
||||
if ((bi - i) >= 0)
|
||||
*n = bt[bi - i];
|
||||
else
|
||||
|
@ -864,8 +813,7 @@ static int b_fget(int *n, int i)
|
|||
* tests whether the given block number n is in the current stack of
|
||||
* current block numbers bt[]
|
||||
*/
|
||||
static int b_test(int n)
|
||||
{
|
||||
static int b_test(int n) {
|
||||
int i = bi;
|
||||
|
||||
while (i >= 0 && n != bt[i])
|
||||
|
@ -881,14 +829,11 @@ static int b_ltest(int a, int b) /* testet ob bt^-1(b) in intervall [0,bt^-1(
|
|||
{
|
||||
int i = 0, er = E_OK;
|
||||
|
||||
if(a!=b)
|
||||
{
|
||||
if (a != b) {
|
||||
er = E_OK;
|
||||
|
||||
while(i<=bi && b!=bt[i])
|
||||
{
|
||||
if(bt[i]==a)
|
||||
{
|
||||
while (i <= bi && b != bt[i]) {
|
||||
if (bt[i] == a) {
|
||||
er = E_NOBLK;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
extern char *lz;
|
||||
|
||||
|
||||
int l_init(void);
|
||||
int ga_lab(void);
|
||||
int gm_lab(void);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* maintained by Cameron Kaiser
|
||||
*
|
||||
* Assembler listing
|
||||
|
@ -31,7 +31,6 @@
|
|||
#include "xal.h"
|
||||
#include "xat.h"
|
||||
|
||||
|
||||
/*********************************************************************************************/
|
||||
/* this is the listing code
|
||||
*
|
||||
|
@ -87,9 +86,7 @@ static char *def_escape_char(char toescape) {
|
|||
|
||||
static formatter_t def_format = {
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
def_escape, def_escape_char
|
||||
};
|
||||
NULL, NULL, NULL, def_escape, def_escape_char };
|
||||
|
||||
static void html_start_listing(char *name) {
|
||||
// really short version for now
|
||||
|
@ -127,13 +124,11 @@ static char *html_escape(char *toescape) {
|
|||
strcpy(q, "<");
|
||||
q += 4;
|
||||
p++;
|
||||
} else
|
||||
if (*p == '&') {
|
||||
} else if (*p == '&') {
|
||||
strcpy(q, "&");
|
||||
q += 5;
|
||||
p++;
|
||||
} else
|
||||
if (*p == '>') {
|
||||
} else if (*p == '>') {
|
||||
strcpy(q, ">");
|
||||
q += 4;
|
||||
p++;
|
||||
|
@ -156,16 +151,9 @@ static char *html_escape_char(char toescape) {
|
|||
return html_escape(buf);
|
||||
}
|
||||
|
||||
static formatter_t html_format = {
|
||||
html_start_listing,
|
||||
NULL,
|
||||
html_set_anchor,
|
||||
html_start_label,
|
||||
html_end_label,
|
||||
NULL,
|
||||
html_end_listing,
|
||||
html_escape, html_escape_char
|
||||
};
|
||||
static formatter_t html_format = { html_start_listing,
|
||||
NULL, html_set_anchor, html_start_label, html_end_label,
|
||||
NULL, html_end_listing, html_escape, html_escape_char };
|
||||
|
||||
static formatter_t *formatp = &def_format;
|
||||
|
||||
|
@ -185,13 +173,15 @@ void list_start(const char *formatname) {
|
|||
}
|
||||
|
||||
if (listfp != NULL) {
|
||||
if (formatp->start_listing != NULL) formatp->start_listing(list_filenamep);
|
||||
if (formatp->start_listing != NULL)
|
||||
formatp->start_listing(list_filenamep);
|
||||
}
|
||||
}
|
||||
|
||||
void list_end() {
|
||||
if (listfp != NULL) {
|
||||
if (formatp->end_listing != NULL) formatp->end_listing();
|
||||
if (formatp->end_listing != NULL)
|
||||
formatp->end_listing();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,7 +197,8 @@ void list_line(int l) {
|
|||
|
||||
/* set file name for the coming listing output */
|
||||
void list_filename(char *fname) {
|
||||
if (list_filenamep == NULL || (fname != NULL && strcmp(fname, list_filenamep) != 0)) {
|
||||
if (list_filenamep == NULL
|
||||
|| (fname != NULL && strcmp(fname, list_filenamep) != 0)) {
|
||||
list_filenamep = fname;
|
||||
list_lineno = 1;
|
||||
list_last_lineno = 0;
|
||||
|
@ -239,12 +230,24 @@ char *list_preamble(char *buf, int lineno, int seg, int pc) {
|
|||
c = '?';
|
||||
/* preamble <segment>':'<address>' ' */
|
||||
switch (seg) {
|
||||
case SEG_ABS: c='A'; break;
|
||||
case SEG_TEXT: c='T'; break;
|
||||
case SEG_BSS: c='B'; break;
|
||||
case SEG_DATA: c='D'; break;
|
||||
case SEG_UNDEF: c='U'; break;
|
||||
case SEG_ZERO: c='Z'; break;
|
||||
case SEG_ABS:
|
||||
c = 'A';
|
||||
break;
|
||||
case SEG_TEXT:
|
||||
c = 'T';
|
||||
break;
|
||||
case SEG_BSS:
|
||||
c = 'B';
|
||||
break;
|
||||
case SEG_DATA:
|
||||
c = 'D';
|
||||
break;
|
||||
case SEG_UNDEF:
|
||||
c = 'U';
|
||||
break;
|
||||
case SEG_ZERO:
|
||||
c = 'Z';
|
||||
break;
|
||||
}
|
||||
buf = buf + list_char(buf, c);
|
||||
buf = buf + list_char(buf, ':');
|
||||
|
@ -254,7 +257,6 @@ char *list_preamble(char *buf, int lineno, int seg, int pc) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* listing/listing_len give the buffer address and length respectively that contains
|
||||
* the token as they are produced by the tokenizer.
|
||||
|
@ -263,7 +265,8 @@ char *list_preamble(char *buf, int lineno, int seg, int pc) {
|
|||
*
|
||||
* Note that both lengths may be zero
|
||||
*/
|
||||
void do_listing(signed char *listing, int listing_len, signed char *bincode, int bincode_len) {
|
||||
void do_listing(signed char *listing, int listing_len, signed char *bincode,
|
||||
int bincode_len) {
|
||||
int i, n_hexb, num_last_line, tmp, overflow;
|
||||
|
||||
char outline[MAXLINE];
|
||||
|
@ -273,12 +276,13 @@ void do_listing(signed char *listing, int listing_len, signed char *bincode, int
|
|||
int lst_pc = (listing[2] << 8) | (listing[1] & 255);
|
||||
|
||||
/* no output file (not even stdout) */
|
||||
if (listfp == NULL) return;
|
||||
|
||||
if (listfp == NULL)
|
||||
return;
|
||||
|
||||
/*printf("do_listing: listing=%p (%d), bincode=%p (%d)\n", listing, listing_len, bincode, bincode_len);*/
|
||||
|
||||
if (bincode_len < 0) bincode_len = -bincode_len;
|
||||
if (bincode_len < 0)
|
||||
bincode_len = -bincode_len;
|
||||
|
||||
/* do we need a separation line? */
|
||||
if (list_lineno > list_last_lineno + 1) {
|
||||
|
@ -289,7 +293,8 @@ void do_listing(signed char *listing, int listing_len, signed char *bincode, int
|
|||
list_last_lineno = list_lineno;
|
||||
|
||||
// could be extended to include the preamble...
|
||||
if (formatp->start_line != NULL) formatp->start_line();
|
||||
if (formatp->start_line != NULL)
|
||||
formatp->start_line();
|
||||
|
||||
buf = list_preamble(buf, list_lineno, lst_seg, lst_pc);
|
||||
|
||||
|
@ -316,8 +321,10 @@ void do_listing(signed char *listing, int listing_len, signed char *bincode, int
|
|||
// make a break
|
||||
buf[0] = 0;
|
||||
fprintf(listfp, "%s\n", outline);
|
||||
if (formatp->end_line != NULL) formatp->end_line();
|
||||
if (formatp->start_line != NULL) formatp->start_line();
|
||||
if (formatp->end_line != NULL)
|
||||
formatp->end_line();
|
||||
if (formatp->start_line != NULL)
|
||||
formatp->start_line();
|
||||
buf = outline;
|
||||
buf = list_preamble(buf, list_lineno, lst_seg, lst_pc + i + 1);
|
||||
}
|
||||
|
@ -339,8 +346,10 @@ void do_listing(signed char *listing, int listing_len, signed char *bincode, int
|
|||
// make a break (Note: with original PC, as now the assembler text follows
|
||||
buf[0] = 0;
|
||||
fprintf(listfp, "%s\n", outline);
|
||||
if (formatp->end_line != NULL) formatp->end_line();
|
||||
if (formatp->start_line != NULL) formatp->start_line();
|
||||
if (formatp->end_line != NULL)
|
||||
formatp->end_line();
|
||||
if (formatp->start_line != NULL)
|
||||
formatp->start_line();
|
||||
buf = outline;
|
||||
buf = list_preamble(buf, list_lineno, lst_seg, lst_pc);
|
||||
i = 0;
|
||||
|
@ -373,7 +382,8 @@ void do_listing(signed char *listing, int listing_len, signed char *bincode, int
|
|||
|
||||
fprintf(listfp, "%s\n", outline);
|
||||
|
||||
if (formatp->end_line != NULL) formatp->end_line();
|
||||
if (formatp->end_line != NULL)
|
||||
formatp->end_line();
|
||||
}
|
||||
|
||||
int list_tokens(char *buf, signed char *input, int len) {
|
||||
|
@ -386,7 +396,8 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
int tabval, operator;
|
||||
signed char format;
|
||||
|
||||
if (inp >= len) return 0;
|
||||
if (inp >= len)
|
||||
return 0;
|
||||
|
||||
tmp = input[inp] & 255;
|
||||
|
||||
|
@ -404,8 +415,7 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
|
||||
if (is_cll == CHEAP) {
|
||||
outp += list_char(buf + outp, '@');
|
||||
} else
|
||||
if (is_cll == UNNAMED_DEF || is_cll == UNNAMED) {
|
||||
} else if (is_cll == UNNAMED_DEF || is_cll == UNNAMED) {
|
||||
outp += list_char(buf + outp, ':');
|
||||
}
|
||||
if (is_cll != UNNAMED) {
|
||||
|
@ -455,13 +465,15 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
|
||||
switch (input[inp]) {
|
||||
case T_CAST:
|
||||
outp += list_string(buf+outp, formatp->escape_char(input[inp+1]));
|
||||
outp += list_string(buf + outp,
|
||||
formatp->escape_char(input[inp + 1]));
|
||||
inp += 2;
|
||||
break;
|
||||
case T_VALUE:
|
||||
/*outp += list_char(buf+outp, 'V');*/
|
||||
/* 24 bit value */
|
||||
tmp = ((input[inp+3]&255)<<16) | ((input[inp+2]&255)<<8) | (input[inp+1]&255);
|
||||
tmp = ((input[inp + 3] & 255) << 16) | ((input[inp + 2] & 255) << 8)
|
||||
| (input[inp + 1] & 255);
|
||||
format = input[inp + 4];
|
||||
outp += list_value(buf + outp, tmp, format);
|
||||
inp += 5;
|
||||
|
@ -475,19 +487,20 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
|
||||
// duplicate label name
|
||||
if (formatp->start_label != NULL) {
|
||||
outp += formatp->start_label(buf+outp, l_get_unique_name(tmp));
|
||||
outp += formatp->start_label(buf + outp,
|
||||
l_get_unique_name(tmp));
|
||||
}
|
||||
if (is_cll == CHEAP) {
|
||||
outp += list_char(buf + outp, '@');
|
||||
} else
|
||||
if (is_cll == UNNAMED || is_cll == UNNAMED_DEF) {
|
||||
} else if (is_cll == UNNAMED || is_cll == UNNAMED_DEF) {
|
||||
outp += list_char(buf + outp, ':');
|
||||
}
|
||||
if (is_cll != UNNAMED) {
|
||||
outp += list_string(buf + outp, name == NULL ? "<null>" : name);
|
||||
}
|
||||
|
||||
if (formatp->end_label != NULL) outp += formatp->end_label(buf+outp);
|
||||
if (formatp->end_label != NULL)
|
||||
outp += formatp->end_label(buf + outp);
|
||||
|
||||
inp += 3;
|
||||
operator = 1; /* check if arithmetic operator follows */
|
||||
|
@ -499,10 +512,12 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
if (input[inp + 3] == '=') {
|
||||
// label definition
|
||||
if (formatp->set_anchor != NULL) {
|
||||
outp += formatp->set_anchor(buf+outp, l_get_unique_name(tmp));
|
||||
outp += formatp->set_anchor(buf + outp,
|
||||
l_get_unique_name(tmp));
|
||||
}
|
||||
}
|
||||
if (is_cll) outp += list_char(buf+outp, '@');
|
||||
if (is_cll)
|
||||
outp += list_char(buf + outp, '@');
|
||||
outp += list_string(buf + outp, name);
|
||||
outp += list_char(buf + outp, input[inp + 3]);
|
||||
inp += 4;
|
||||
|
@ -533,12 +548,15 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
tmp = ((input[inp + 5] & 255) << 8) | (input[inp + 4] & 255);
|
||||
name = l_get_name(tmp, &is_cll);
|
||||
if (formatp->start_label != NULL) {
|
||||
outp += formatp->start_label(buf+outp, l_get_unique_name(tmp));
|
||||
outp += formatp->start_label(buf + outp,
|
||||
l_get_unique_name(tmp));
|
||||
}
|
||||
if (is_cll) outp += list_char(buf+outp, '@');
|
||||
if (is_cll)
|
||||
outp += list_char(buf + outp, '@');
|
||||
outp += list_string(buf + outp, name);
|
||||
|
||||
if (formatp->end_label != NULL) outp += formatp->end_label(buf+outp);
|
||||
if (formatp->end_label != NULL)
|
||||
outp += formatp->end_label(buf + outp);
|
||||
/*
|
||||
outp += list_byte(buf+outp, input[inp+1]);
|
||||
outp += list_char(buf+outp, '#');
|
||||
|
@ -573,7 +591,8 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
default:
|
||||
c = input[inp];
|
||||
if (c > 31) {
|
||||
outp += list_string(buf+outp, formatp->escape_char(input[inp]));
|
||||
outp += list_string(buf + outp,
|
||||
formatp->escape_char(input[inp]));
|
||||
} else {
|
||||
outp += list_char(buf + outp, '\'');
|
||||
outp += list_byte(buf + outp, input[inp]);
|
||||
|
@ -594,8 +613,7 @@ int list_tokens(char *buf, signed char *input, int len) {
|
|||
// another operator is expected after the bracket
|
||||
}
|
||||
}
|
||||
end:
|
||||
return outp;
|
||||
end: return outp;
|
||||
}
|
||||
|
||||
int list_string(char *buf, char *string) {
|
||||
|
@ -624,8 +642,7 @@ int list_value(char *buf, int val, signed char format) {
|
|||
if (val & (255 << 16)) {
|
||||
p += list_byte(buf + p, val >> 16);
|
||||
p += list_word(buf + p, val);
|
||||
} else
|
||||
if (val & (255<<8)) {
|
||||
} else if (val & (255 << 8)) {
|
||||
p += list_word(buf + p, val);
|
||||
} else {
|
||||
p += list_byte(buf + p, val);
|
||||
|
@ -636,8 +653,7 @@ int list_value(char *buf, int val, signed char format) {
|
|||
if (val & (255 << 16)) {
|
||||
p += list_byte_f(buf + p, val >> 16, '%');
|
||||
p += list_word_f(buf + p, val, '%');
|
||||
} else
|
||||
if (val & (255<<8)) {
|
||||
} else if (val & (255 << 8)) {
|
||||
p += list_word_f(buf + p, val, '%');
|
||||
} else {
|
||||
p += list_byte_f(buf + p, val, '%');
|
||||
|
@ -664,8 +680,7 @@ int list_value(char *buf, int val, signed char format) {
|
|||
if (val & (255 << 16)) {
|
||||
p += list_byte(buf + p, val >> 16);
|
||||
p += list_word(buf + p, val);
|
||||
} else
|
||||
if (val & (255<<8)) {
|
||||
} else if (val & (255 << 8)) {
|
||||
p += list_word(buf + p, val);
|
||||
} else {
|
||||
p += list_byte(buf + p, val);
|
||||
|
@ -746,5 +761,3 @@ int list_nibble_f(char *buf, int outnib, signed char format) {
|
|||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ void list_line(int l); /* set line number for the coming listing output
|
|||
void list_filename(char *fname);/* set file name for the coming listing output */
|
||||
|
||||
// list a single line/token set
|
||||
void do_listing(signed char *listing, int listing_len, signed char *bincode, int bincode_len);
|
||||
void do_listing(signed char *listing, int listing_len, signed char *bincode,
|
||||
int bincode_len);
|
||||
|
||||
#endif /* __XA65_XALISTING_H__ */
|
||||
|
|
38
xa/src/xam.c
38
xa/src/xam.c
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* Memory manager/malloc() stub module
|
||||
*
|
||||
|
@ -41,8 +41,7 @@ void reg_include(char *path) {
|
|||
}
|
||||
}
|
||||
|
||||
FILE *xfopen(const char *fn,const char *mode)
|
||||
{
|
||||
FILE* xfopen(const char *fn, const char *mode) {
|
||||
FILE *file;
|
||||
char c, *cp, n[MAXLINE], path[MAXLINE];
|
||||
char xname[MAXLINE], n2[MAXLINE];
|
||||
|
@ -60,28 +59,26 @@ FILE *xfopen(const char *fn,const char *mode)
|
|||
|
||||
//printf("name=%s, xname=%s, mode=%s\n",fn,xname, mode);
|
||||
|
||||
if(mode[0]=='r')
|
||||
{
|
||||
if (mode[0] == 'r') {
|
||||
if ((file = fopen(fn, mode)) == NULL
|
||||
&& (file = fopen(xname, mode)) == NULL) {
|
||||
for (i = 0; (!file) && (i < ninc); i++) {
|
||||
strcpy(n, nip[i]);
|
||||
c = n[(int) strlen(n) - 1];
|
||||
if(c!=DIRCHAR) strcat(n,DIRCSTRING);
|
||||
if (c != DIRCHAR)
|
||||
strcat(n, DIRCSTRING);
|
||||
strcpy(n2, n);
|
||||
strcat(n2, xname);
|
||||
strcat(n, fn);
|
||||
file = fopen(n, mode);
|
||||
if(!file) file=fopen(n2,mode);
|
||||
if (!file)
|
||||
file = fopen(n2, mode);
|
||||
}
|
||||
if((!file) && (cp=getenv("XAINPUT"))!=NULL)
|
||||
{
|
||||
if ((!file) && (cp = getenv("XAINPUT")) != NULL) {
|
||||
strcpy(path, cp);
|
||||
cp = strtok(path, ",");
|
||||
while(cp && !file)
|
||||
{
|
||||
if(cp[0])
|
||||
{
|
||||
while (cp && !file) {
|
||||
if (cp[0]) {
|
||||
strcpy(n, cp);
|
||||
c = n[(int) strlen(n) - 1];
|
||||
if (c != DIRCHAR && c != ':')
|
||||
|
@ -90,26 +87,23 @@ FILE *xfopen(const char *fn,const char *mode)
|
|||
strcat(n2, xname);
|
||||
strcat(n, fn);
|
||||
file = fopen(n, mode);
|
||||
if(!file) file=fopen(n2,mode);
|
||||
if (!file)
|
||||
file = fopen(n2, mode);
|
||||
}
|
||||
cp = strtok(NULL, ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if((cp=getenv("XAOUTPUT"))!=NULL)
|
||||
{
|
||||
} else {
|
||||
if ((cp = getenv("XAOUTPUT")) != NULL) {
|
||||
strcpy(n, cp);
|
||||
if(n[0])
|
||||
{
|
||||
if (n[0]) {
|
||||
c = n[(int) strlen(n) - 1];
|
||||
if (c != DIRCHAR && c != ':')
|
||||
strcat(n, DIRCSTRING);
|
||||
}
|
||||
cp = strrchr(fn, DIRCHAR);
|
||||
if(!cp)
|
||||
{
|
||||
if (!cp) {
|
||||
cp = strrchr(fn, ':');
|
||||
if (!cp)
|
||||
cp = (char*) fn;
|
||||
|
|
14
xa/src/xao.c
14
xa/src/xao.c
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* Options module (handles pass options and writing them out to disk)
|
||||
*
|
||||
|
@ -40,17 +40,19 @@ void set_fopt(int l, signed char *buf, int reallen) {
|
|||
/*printf("set_fopt(%s, l=%d\n",buf,l);*/
|
||||
while (afile->fo.mlist <= afile->fo.nlist) {
|
||||
afile->fo.mlist += 5;
|
||||
afile->fo.olist = realloc(afile->fo.olist, afile->fo.mlist*sizeof(Fopt));
|
||||
afile->fo.olist = realloc(afile->fo.olist,
|
||||
afile->fo.mlist * sizeof(Fopt));
|
||||
if (!afile->fo.olist) {
|
||||
fprintf(stderr, "Fatal: Couldn't alloc memory (%lu bytes) for fopt list!\n",
|
||||
(unsigned long)(
|
||||
afile->fo.mlist*sizeof(Fopt)));
|
||||
fprintf(stderr,
|
||||
"Fatal: Couldn't alloc memory (%lu bytes) for fopt list!\n",
|
||||
(unsigned long) (afile->fo.mlist * sizeof(Fopt)));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
afile->fo.olist[afile->fo.nlist].text = malloc(l);
|
||||
if (!afile->fo.olist[afile->fo.nlist].text) {
|
||||
fprintf(stderr, "Fatal: Couldn't alloc memory (%d bytes) for fopt!\n",l);
|
||||
fprintf(stderr, "Fatal: Couldn't alloc memory (%d bytes) for fopt!\n",
|
||||
l);
|
||||
exit(1);
|
||||
}
|
||||
memcpy(afile->fo.olist[afile->fo.nlist].text, buf, l);
|
||||
|
|
318
xa/src/xap.c
318
xa/src/xap.c
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Maintained by Cameron Kaiser
|
||||
*
|
||||
* File handling and preprocessor (also see xaa.c) module
|
||||
|
@ -65,10 +65,9 @@ static int pp_error(char*);
|
|||
static int quotebs = 0;
|
||||
static int inquote = 0;
|
||||
|
||||
static char *cmd[]={
|
||||
"echo","include","define","undef","printdef","print","error", /* VALBEF */
|
||||
"ifdef","ifndef","else","endif",
|
||||
"ifldef","iflused","if" }; /* ANZBEF */
|
||||
static char *cmd[] = { "echo", "include", "define", "undef", "printdef",
|
||||
"print", "error", /* VALBEF */
|
||||
"ifdef", "ifndef", "else", "endif", "ifldef", "iflused", "if" }; /* ANZBEF */
|
||||
|
||||
static int (*func[])(char*) = {pp_echo,icl_open,pp_define,pp_undef,
|
||||
pp_prdef,pp_print,pp_error,pp_ifdef,pp_ifndef,
|
||||
|
@ -88,20 +87,18 @@ static int loopfl;
|
|||
static Datei flist[MAXFILE + 1];
|
||||
static char in_line[MAXLINE];
|
||||
|
||||
int pp_comand(char *t)
|
||||
{
|
||||
int pp_comand(char *t) {
|
||||
int i, l, er = 1;
|
||||
|
||||
i = tcompare(t, cmd, ANZBEF);
|
||||
|
||||
if(i>=0)
|
||||
{
|
||||
if (i >= 0) {
|
||||
if (loopfl && (i < VALBEF))
|
||||
er = 0;
|
||||
else
|
||||
{
|
||||
else {
|
||||
l = (int) strlen(cmd[i]);
|
||||
while(isspace(t[l])) l++;
|
||||
while (isspace(t[l]))
|
||||
l++;
|
||||
|
||||
er = (*func[i])(t + l);
|
||||
}
|
||||
|
@ -109,8 +106,7 @@ int pp_comand(char *t)
|
|||
return (er);
|
||||
}
|
||||
|
||||
int pp_ifdef(char *t)
|
||||
{
|
||||
int pp_ifdef(char *t) {
|
||||
/* int x;
|
||||
printf("t=%s\n",t);
|
||||
x=searchdef(t);
|
||||
|
@ -120,83 +116,71 @@ int pp_ifdef(char *t)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int pp_ifndef(char *t)
|
||||
{
|
||||
int pp_ifndef(char *t) {
|
||||
loopfl = (loopfl << 1) + (searchdef(t) ? 1 : 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pp_ifldef(char *t)
|
||||
{
|
||||
int pp_ifldef(char *t) {
|
||||
loopfl = (loopfl << 1) + (ll_pdef(t) ? 1 : 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pp_iflused(char *t)
|
||||
{
|
||||
int pp_iflused(char *t) {
|
||||
int n;
|
||||
loopfl = (loopfl << 1) + (ll_search(t, &n, STD) ? 1 : 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pp_echo(char *t)
|
||||
{
|
||||
int pp_echo(char *t) {
|
||||
int er;
|
||||
|
||||
if ((er = pp_replace(s, t, -1, rlist)))
|
||||
errout(er);
|
||||
else
|
||||
{
|
||||
else {
|
||||
logout(s);
|
||||
logout("\n");
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pp_print(char *t)
|
||||
{
|
||||
int pp_print(char *t) {
|
||||
int f, a, er;
|
||||
|
||||
logout(t);
|
||||
if((er=pp_replace(s,t,-1,rlist)))
|
||||
{
|
||||
if ((er = pp_replace(s, t, -1, rlist))) {
|
||||
logout("\n");
|
||||
errout(er);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
logout("=");
|
||||
logout(s);
|
||||
logout("=");
|
||||
er = b_term(s, &a, &f, pc[segment]);
|
||||
if(er)
|
||||
{
|
||||
if (er) {
|
||||
logout("\n");
|
||||
errout(er);
|
||||
} else {
|
||||
sprintf(s, "%d\n", a);
|
||||
logout(s);
|
||||
}
|
||||
else
|
||||
{ sprintf(s,"%d\n",a); logout(s); }
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pp_error(char *t)
|
||||
{
|
||||
int pp_error(char *t) {
|
||||
/* the offending line is printed for us */
|
||||
return E_UERROR;
|
||||
}
|
||||
|
||||
int pp_if(char *t)
|
||||
{
|
||||
int pp_if(char *t) {
|
||||
int a, f, l, er;
|
||||
|
||||
/* XXX: #if XYZ, if XYZ is not defined, XYZ gets treated as a label. */
|
||||
|
||||
if ((er = pp_replace(s, t, -1, rlist))) {
|
||||
errout(er);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
dsb_len = 1;
|
||||
f = b_term(s, &a, &l, pc[segment]);
|
||||
dsb_len = 0;
|
||||
|
@ -209,21 +193,18 @@ int pp_if(char *t)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int pp_else(char *t)
|
||||
{
|
||||
int pp_else(char *t) {
|
||||
(void) t; /* quench warning */
|
||||
loopfl ^= 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pp_endif(char *t)
|
||||
{
|
||||
int pp_endif(char *t) {
|
||||
(void) t; /* quench warning */
|
||||
loopfl = loopfl >> 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* stub for handling CPP directives */
|
||||
int pp_cpp(char *t) {
|
||||
char name[MAXLINE];
|
||||
|
@ -258,23 +239,20 @@ int pp_undef(char *t) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int pp_prdef(char *t)
|
||||
{
|
||||
int pp_prdef(char *t) {
|
||||
char *x;
|
||||
int i, j;
|
||||
|
||||
if((i=searchdef(t)))
|
||||
{
|
||||
if ((i = searchdef(t))) {
|
||||
i += rlist;
|
||||
x = liste[i].search;
|
||||
sprintf(s, "\n%s", x);
|
||||
if(liste[i].p_anz)
|
||||
{
|
||||
if (liste[i].p_anz) {
|
||||
sprintf(s + strlen(s), "(");
|
||||
for(j=0;j<liste[i].p_anz;j++)
|
||||
{
|
||||
for (j = 0; j < liste[i].p_anz; j++) {
|
||||
x += strlen(x) + 1;
|
||||
sprintf(s+strlen(s),"%s%c",x,(liste[i].p_anz-j-1) ? ',' : ')');
|
||||
sprintf(s + strlen(s), "%s%c", x,
|
||||
(liste[i].p_anz - j - 1) ? ',' : ')');
|
||||
}
|
||||
}
|
||||
sprintf(s + strlen(s), "=%s\n", liste[i].replace);
|
||||
|
@ -283,14 +261,13 @@ int pp_prdef(char *t)
|
|||
return (E_OK);
|
||||
}
|
||||
|
||||
int searchdef(char *t)
|
||||
{
|
||||
int searchdef(char *t) {
|
||||
int i = 0, j, k, l = 0;
|
||||
|
||||
while(t[l]!=' ' && t[l]!='\0') l++;
|
||||
while (t[l] != ' ' && t[l] != '\0')
|
||||
l++;
|
||||
|
||||
if(rlist)
|
||||
{
|
||||
if (rlist) {
|
||||
i = hashindex[hashcode(t, l)];
|
||||
|
||||
do /*for(i=0;i<rlist;i++)*/
|
||||
|
@ -298,15 +275,14 @@ int searchdef(char *t)
|
|||
k = liste[i].s_len;
|
||||
j = 0;
|
||||
|
||||
if(k && (k==l))
|
||||
{
|
||||
while((t[j]==liste[i].search[j])&&j<k) j++;
|
||||
if (k && (k == l)) {
|
||||
while ((t[j] == liste[i].search[j]) && j < k)
|
||||
j++;
|
||||
if (j == k)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!i)
|
||||
{
|
||||
if (!i) {
|
||||
i = rlist;
|
||||
break;
|
||||
}
|
||||
|
@ -319,28 +295,23 @@ int searchdef(char *t)
|
|||
return (i - rlist);
|
||||
}
|
||||
|
||||
int ga_pp(void)
|
||||
{
|
||||
int ga_pp(void) {
|
||||
return (rlist);
|
||||
}
|
||||
|
||||
int gm_pp(void)
|
||||
{
|
||||
int gm_pp(void) {
|
||||
return (ANZDEF);
|
||||
}
|
||||
|
||||
long gm_ppm(void)
|
||||
{
|
||||
long gm_ppm(void) {
|
||||
return (MAXPP);
|
||||
}
|
||||
|
||||
long ga_ppm(void)
|
||||
{
|
||||
long ga_ppm(void) {
|
||||
return (MAXPP - memfre);
|
||||
}
|
||||
|
||||
int pp_define(char *k)
|
||||
{
|
||||
int pp_define(char *k) {
|
||||
int i, er = E_OK, hash, rl;
|
||||
char h[MAXLINE * 2], *t;
|
||||
unsigned int j;
|
||||
|
@ -363,23 +334,23 @@ int pp_define(char *k)
|
|||
liste[rl].s_len = i;
|
||||
liste[rl].p_anz = 0;
|
||||
|
||||
|
||||
/* printf("define:%s\nlen1=%d\n",liste[rl].search,liste[rl].s_len);
|
||||
getchar();
|
||||
*/
|
||||
|
||||
if(t[i]=='(')
|
||||
{
|
||||
while(t[i]!=')' && t[i]!='\0')
|
||||
{
|
||||
if (t[i] == '(') {
|
||||
while (t[i] != ')' && t[i] != '\0') {
|
||||
i++;
|
||||
liste[rl].p_anz++;
|
||||
// skip whitespace before parameter name
|
||||
while(isspace(t[i])) i++;
|
||||
while (isspace(t[i]))
|
||||
i++;
|
||||
// find length
|
||||
for(j=0; (!isspace(t[i+j])) && t[i+j]!=')' && t[i+j]!=',' && t[i+j]!='\0';j++);
|
||||
if(j<memfre)
|
||||
{
|
||||
for (j = 0;
|
||||
(!isspace(t[i + j])) && t[i + j] != ')' && t[i + j] != ','
|
||||
&& t[i + j] != '\0'; j++)
|
||||
;
|
||||
if (j < memfre) {
|
||||
strncpy(mem, t + i, j);
|
||||
mem += j;
|
||||
*mem++ = '\0';
|
||||
|
@ -387,7 +358,8 @@ int pp_define(char *k)
|
|||
}
|
||||
i += j;
|
||||
// skip trailing whitespace after parameter name
|
||||
while(isspace(t[i])) i++;
|
||||
while (isspace(t[i]))
|
||||
i++;
|
||||
}
|
||||
if (t[i] == ')')
|
||||
i++;
|
||||
|
@ -424,8 +396,7 @@ int pp_define(char *k)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
if(!er)
|
||||
{
|
||||
if (!er) {
|
||||
hash = hashcode(liste[rl].search, liste[rl].s_len);
|
||||
liste[rl].nextindex = hashindex[hash];
|
||||
hashindex[hash] = rl;
|
||||
|
@ -435,8 +406,7 @@ int pp_define(char *k)
|
|||
return (er);
|
||||
}
|
||||
|
||||
int tcompare(char s[],char *v[], int n)
|
||||
{
|
||||
int tcompare(char s[], char *v[], int n) {
|
||||
int i, j, l;
|
||||
static char t[MAXLINE];
|
||||
|
||||
|
@ -444,12 +414,10 @@ int tcompare(char s[],char *v[], int n)
|
|||
t[i] = tolower(s[i]);
|
||||
t[i] = '\0';
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for (i = 0; i < n; i++) {
|
||||
l = (int) strlen(v[i]);
|
||||
|
||||
for(j=0;j<l;j++)
|
||||
{
|
||||
for (j = 0; j < l; j++) {
|
||||
if (t[j] != v[i][j])
|
||||
break;
|
||||
}
|
||||
|
@ -487,8 +455,8 @@ static int check_name(char *t, int n) {
|
|||
* blist ->
|
||||
*
|
||||
*/
|
||||
static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int *l, int blist)
|
||||
{
|
||||
static int pp_replace_part(char *to, char *t, int n, int sl, int recursive,
|
||||
int *l, int blist) {
|
||||
int er = E_OK;
|
||||
int i, d;
|
||||
char c;
|
||||
|
@ -507,9 +475,7 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
|
||||
// does it have parameters?
|
||||
|
||||
|
||||
if(liste[n].p_anz)
|
||||
{
|
||||
if (liste[n].p_anz) {
|
||||
// yes, we have parameters, so we need to pp_replace them
|
||||
// as well.
|
||||
char fti[MAXLINE], fto[MAXLINE];
|
||||
|
@ -520,8 +486,7 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
// boundary checks ...
|
||||
if (blist + liste[n].p_anz >= ANZDEF || memfre < MAXLINE * 2)
|
||||
er = E_NOMEM;
|
||||
else
|
||||
{
|
||||
else {
|
||||
// ... passed
|
||||
// y points to the char behind the input name (i.e. the '(')
|
||||
char *y = t + sl;
|
||||
|
@ -533,17 +498,14 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
if (*y != '(') {
|
||||
// no. Should probably get an own error (E_PARAMETER_EXPECTED)
|
||||
er = E_SYNTAX;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// mx now points to next free memory (mem current pointer in text table)
|
||||
char *mx = mem - 1;
|
||||
// walk through the pp parameters
|
||||
// by creating "fake" preprocessor definitions at the end
|
||||
// of the current definition list, i.e. in liste[] after index
|
||||
// rlist.
|
||||
for(i=0;i<liste[n].p_anz;i++)
|
||||
{
|
||||
for (i = 0; i < liste[n].p_anz; i++) {
|
||||
char c;
|
||||
int hkfl = 0; // quote flag
|
||||
int klfl = 0; // brackets counter
|
||||
|
@ -561,17 +523,11 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
c = *(++mx) = *(++y);
|
||||
// copy over the other characters
|
||||
while (c != '\0'
|
||||
&& ((hkfl!=0
|
||||
|| klfl!=0)
|
||||
|| (c!=','
|
||||
&& c!=')')
|
||||
)
|
||||
)
|
||||
{
|
||||
&& ((hkfl != 0 || klfl != 0)
|
||||
|| (c != ',' && c != ')'))) {
|
||||
if (c == '\"')
|
||||
hkfl = hkfl ^ 1;
|
||||
if(!hkfl)
|
||||
{
|
||||
if (!hkfl) {
|
||||
if (c == '(')
|
||||
klfl++;
|
||||
if (c == ')')
|
||||
|
@ -584,8 +540,7 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
// if i is for the last parameter, then check if the
|
||||
// last copied char was ')', otherwise it should be ','
|
||||
// as separator for the next parameter
|
||||
if(c!=((i==liste[n].p_anz-1) ? ')' : ','))
|
||||
{
|
||||
if (c != ((i == liste[n].p_anz - 1) ? ')' : ',')) {
|
||||
er = E_ANZPAR;
|
||||
// note: this break only exits the innermost loop!
|
||||
break;
|
||||
|
@ -624,7 +579,8 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
if (!er) {
|
||||
// replace the tokens in the parameter, adding possible pseudo params
|
||||
// on top of the liste[] into nfto
|
||||
er=pp_replace(nfto,nfwas,-1,blist+liste[n].p_anz);
|
||||
er = pp_replace(nfto, nfwas, -1,
|
||||
blist + liste[n].p_anz);
|
||||
}
|
||||
#ifdef DEBUG_RECMAC
|
||||
printf("-%s=%s\n",liste[rlist+i].search,liste[rlist+i].replace);
|
||||
|
@ -681,7 +637,8 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
printf("replace macro: recursive=%d, blist=%d, -> b=%d\n", recursive, blist, blist+liste[n].p_anz);
|
||||
printf(" from: %s\n", fti);
|
||||
#endif
|
||||
er=pp_replace(fto,fti,recursive ? 0 : blist,blist+liste[n].p_anz);
|
||||
er = pp_replace(fto, fti, recursive ? 0 : blist,
|
||||
blist + liste[n].p_anz);
|
||||
#ifdef DEBUG_RECMAC
|
||||
printf(" to: %s\n", fto);
|
||||
#endif
|
||||
|
@ -753,8 +710,7 @@ static int pp_replace_part(char *to, char *t, int n, int sl, int recursive, int
|
|||
* parameters
|
||||
*
|
||||
*/
|
||||
int pp_replace(char *to, char *ti, int a,int b)
|
||||
{
|
||||
int pp_replace(char *to, char *ti, int a, int b) {
|
||||
char *t = to;
|
||||
int l, n, sl, er = E_OK;
|
||||
int ld; // length of name/token to analyse
|
||||
|
@ -767,22 +723,21 @@ int pp_replace(char *to, char *ti, int a,int b)
|
|||
(void) strcpy(t, ti);
|
||||
|
||||
// if there are replacements in the list of replacements
|
||||
if(rlist)
|
||||
{
|
||||
if (rlist) {
|
||||
// loop over the whole input
|
||||
while(t[0]!='\0' && t[0] != ';')
|
||||
{
|
||||
while (t[0] != '\0' && t[0] != ';') {
|
||||
// skip over the whitespace
|
||||
// comment handling is NASTY NASTY NASTY
|
||||
// but I currently don't see another way, as comments and colons
|
||||
// can (and do) appear in preprocessor replacements
|
||||
char quotefl = 0;
|
||||
char commentfl = 0;
|
||||
while((t[0] != 0) && (quotefl || commentfl || ((!isalpha(t[0]) && t[0]!='_')))) {
|
||||
while ((t[0] != 0)
|
||||
&& (quotefl || commentfl
|
||||
|| ((!isalpha(t[0]) && t[0] != '_')))) {
|
||||
if (t[0] == '\0') {
|
||||
break; /*return(E_OK);*/
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
if (t[0] == ';' && !quotefl) {
|
||||
commentfl = 1;
|
||||
}
|
||||
|
@ -796,8 +751,7 @@ int pp_replace(char *to, char *ti, int a,int b)
|
|||
if (t[0] == quotefl) {
|
||||
quotefl = 0;
|
||||
}
|
||||
} else
|
||||
if (t[0] == '"' || t[0] == '\'') {
|
||||
} else if (t[0] == '"' || t[0] == '\'') {
|
||||
quotefl = t[0];
|
||||
}
|
||||
t++;
|
||||
|
@ -806,7 +760,8 @@ int pp_replace(char *to, char *ti, int a,int b)
|
|||
}
|
||||
|
||||
// determine the length of the name
|
||||
for(l=0;isalnum(t[l])||t[l]=='_';l++);
|
||||
for (l = 0; isalnum(t[l]) || t[l] == '_'; l++)
|
||||
;
|
||||
// store in ld
|
||||
ld = l;
|
||||
#ifdef DEBUG_RECMAC
|
||||
|
@ -815,8 +770,7 @@ int pp_replace(char *to, char *ti, int a,int b)
|
|||
|
||||
// the following if() is executed when being called from an
|
||||
// 'external' context, i.e. not from a recursion
|
||||
if(a<0)
|
||||
{
|
||||
if (a < 0) {
|
||||
// when called from an external context, not by recursion
|
||||
|
||||
// compute hashcode for the name for the search index entry (liste[n])
|
||||
|
@ -832,8 +786,7 @@ int pp_replace(char *to, char *ti, int a,int b)
|
|||
printf("macro entry: name=%s, sl=%d, p_anz=%d\n", liste[n].search, sl, liste[n].p_anz);
|
||||
#endif
|
||||
// does pp definition match what we have found?
|
||||
if(sl && (sl==l) && check_name(t, n))
|
||||
{
|
||||
if (sl && (sl == l) && check_name(t, n)) {
|
||||
er = pp_replace_part(to, t, n, sl, 0, &l, b);
|
||||
if (er != E_OK) {
|
||||
return er;
|
||||
|
@ -847,18 +800,15 @@ int pp_replace(char *to, char *ti, int a,int b)
|
|||
n = liste[n].nextindex;
|
||||
|
||||
} while (1);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
// called when in recursive call
|
||||
// loop over all the replacement entries from the given b down to 0
|
||||
// that allows to replace the parameters first (as they were added at
|
||||
// the end of the list)
|
||||
for(n=b-1;n>=a;n--)
|
||||
{
|
||||
for (n = b - 1; n >= a; n--) {
|
||||
sl = liste[n].s_len;
|
||||
|
||||
if(sl && (sl==l) && check_name(t, n))
|
||||
{
|
||||
if (sl && (sl == l) && check_name(t, n)) {
|
||||
er = pp_replace_part(to, t, n, sl, 1, &l, b);
|
||||
break;
|
||||
}
|
||||
|
@ -873,8 +823,7 @@ int pp_replace(char *to, char *ti, int a,int b)
|
|||
return (E_OK);
|
||||
}
|
||||
|
||||
int pp_init(void)
|
||||
{
|
||||
int pp_init(void) {
|
||||
int er;
|
||||
|
||||
for (er = 0; er < 256; er++)
|
||||
|
@ -884,7 +833,8 @@ int pp_init(void)
|
|||
|
||||
er = 0;
|
||||
mem = malloc(MAXPP);
|
||||
if(!mem) er=E_NOMEM;
|
||||
if (!mem)
|
||||
er = E_NOMEM;
|
||||
|
||||
memfre = MAXPP;
|
||||
rlist = 0;
|
||||
|
@ -892,18 +842,20 @@ int pp_init(void)
|
|||
nff = 1;
|
||||
if (!er) {
|
||||
liste = malloc((long) ANZDEF * sizeof(List));
|
||||
if(!liste) er=E_NOMEM;
|
||||
if (!liste)
|
||||
er = E_NOMEM;
|
||||
if (!er && !xa23) {
|
||||
er = pp_define("XA_MAJOR " progmajor);
|
||||
if (!er) er = pp_define("XA_MINOR " progminor);
|
||||
if (!er) er = pp_define("XA_PATCH " progpatch);
|
||||
if (!er)
|
||||
er = pp_define("XA_MINOR " progminor);
|
||||
if (!er)
|
||||
er = pp_define("XA_PATCH " progpatch);
|
||||
}
|
||||
}
|
||||
return (er);
|
||||
}
|
||||
|
||||
int pp_open(char *name)
|
||||
{
|
||||
int pp_open(char *name) {
|
||||
FILE *fp;
|
||||
int l;
|
||||
|
||||
|
@ -927,29 +879,30 @@ int pp_open(char *name)
|
|||
return (fp == NULL);
|
||||
}
|
||||
|
||||
void pp_close(void)
|
||||
{
|
||||
void pp_close(void) {
|
||||
if (flist[fsp].bdepth != b_depth()) {
|
||||
fprintf(stderr, "Blocks not consistent in file %s: start depth=%d, end depth=%d\n",
|
||||
fprintf(stderr,
|
||||
"Blocks not consistent in file %s: start depth=%d, end depth=%d\n",
|
||||
flist[fsp].fname, flist[fsp].bdepth, b_depth());
|
||||
}
|
||||
fclose(flist[fsp].filep);
|
||||
}
|
||||
|
||||
void pp_end(void) { }
|
||||
void pp_end(void) {
|
||||
}
|
||||
|
||||
Datei* pp_getidat(void) {
|
||||
return &flist[fsp];
|
||||
}
|
||||
|
||||
int icl_close(int *c)
|
||||
{
|
||||
int icl_close(int *c) {
|
||||
*c = '\n';
|
||||
if (!fsp)
|
||||
return (E_EOF);
|
||||
|
||||
if (flist[fsp].bdepth != b_depth()) {
|
||||
fprintf(stderr, "Blocks not consistent in file %s: start depth=%d, end depth=%d\n",
|
||||
fprintf(stderr,
|
||||
"Blocks not consistent in file %s: start depth=%d, end depth=%d\n",
|
||||
flist[fsp].fname, flist[fsp].bdepth, b_depth());
|
||||
}
|
||||
|
||||
|
@ -959,8 +912,7 @@ int icl_close(int *c)
|
|||
return (E_OK);
|
||||
}
|
||||
|
||||
int icl_open(char *tt)
|
||||
{
|
||||
int icl_open(char *tt) {
|
||||
FILE *fp2;
|
||||
char *namep;
|
||||
int len, j, i = 0;
|
||||
|
@ -1006,9 +958,7 @@ int icl_open(char *tt)
|
|||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int pgetline(char *t)
|
||||
{
|
||||
int pgetline(char *t) {
|
||||
int c, er = E_OK;
|
||||
int rlen, tlen;
|
||||
char *p = 0;
|
||||
|
@ -1022,11 +972,13 @@ int pgetline(char *t)
|
|||
int is_continuation = 0;
|
||||
tlen = 0; // start of current line in in_line[]
|
||||
do {
|
||||
c=fgetline(in_line + tlen, MAXLINE - tlen, &rlen, flist[fsp].filep);
|
||||
c = fgetline(in_line + tlen, MAXLINE - tlen, &rlen,
|
||||
flist[fsp].filep);
|
||||
//fprintf(stderr, "fgetline -> c=%02x, rlen->%d, t->%s\n", c, rlen, in_line+tlen);
|
||||
|
||||
/* check for continuation lines */
|
||||
is_continuation = ((c == '\n') && (rlen > 0) && (in_line[tlen + rlen - 1]=='\\'));
|
||||
is_continuation = ((c == '\n') && (rlen > 0)
|
||||
&& (in_line[tlen + rlen - 1] == '\\'));
|
||||
if (is_continuation) {
|
||||
// cut off the continuation character
|
||||
rlen--;
|
||||
|
@ -1036,16 +988,13 @@ int pgetline(char *t)
|
|||
tlen += rlen;
|
||||
} while (is_continuation);
|
||||
|
||||
if(in_line[0]=='#' || in_line[0] == altppchar)
|
||||
{
|
||||
if (in_line[0] == '#' || in_line[0] == altppchar) {
|
||||
if (in_line[1] == ' ') { /* cpp comment -- pp_comand doesn't
|
||||
handle this right */
|
||||
er = pp_cpp(in_line + 1);
|
||||
} else {
|
||||
if((er=pp_comand(in_line+1)))
|
||||
{
|
||||
if(er!=1)
|
||||
{
|
||||
if ((er = pp_comand(in_line + 1))) {
|
||||
if (er != 1) {
|
||||
logout(in_line);
|
||||
logout("\n");
|
||||
}
|
||||
|
@ -1058,8 +1007,8 @@ int pgetline(char *t)
|
|||
if (c == EOF) {
|
||||
if (loopfl && fsp) {
|
||||
char bletch[MAXLINE];
|
||||
sprintf(bletch,
|
||||
"at end of included file %s:\n", flist[fsp].fname);
|
||||
sprintf(bletch, "at end of included file %s:\n",
|
||||
flist[fsp].fname);
|
||||
logout(bletch);
|
||||
errout(W_OPENPP);
|
||||
}
|
||||
|
@ -1072,7 +1021,6 @@ int pgetline(char *t)
|
|||
errout(E_OPENPP);
|
||||
}
|
||||
|
||||
|
||||
if (!er || loopfl) {
|
||||
in_line[0] = '\0';
|
||||
}
|
||||
|
@ -1102,12 +1050,10 @@ int pgetline(char *t)
|
|||
return (er);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* smart getc that can skip C comment blocks */
|
||||
int rgetc(FILE *fp)
|
||||
{
|
||||
int rgetc(FILE *fp) {
|
||||
int incomment;
|
||||
int c;
|
||||
static int d;
|
||||
|
@ -1116,8 +1062,7 @@ int rgetc(FILE *fp)
|
|||
|
||||
incomment = 0;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
restart:
|
||||
|
||||
/* we had a look-ahead to see if two-char sequence was received? */
|
||||
|
@ -1141,8 +1086,7 @@ int rgetc(FILE *fp)
|
|||
|
||||
/* check for start of comment anyway, to allow for nested comments */
|
||||
/* only allow this with 2.3 compatibility */
|
||||
if(!inquote && c=='/' && (xa23 || !incomment))
|
||||
{
|
||||
if (!inquote && c == '/' && (xa23 || !incomment)) {
|
||||
d = getc(fp);
|
||||
|
||||
// C++ double slash comment
|
||||
|
@ -1154,8 +1098,7 @@ int rgetc(FILE *fp)
|
|||
flist[fsp].fline++;
|
||||
nlf = 1;
|
||||
}
|
||||
} else
|
||||
if (d == '*') {
|
||||
} else if (d == '*') {
|
||||
/* start block comment */
|
||||
incomment++;
|
||||
/* convene normal processing */
|
||||
|
@ -1165,7 +1108,6 @@ int rgetc(FILE *fp)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* here we are in a dilemma. If we interpret quotes in comments,
|
||||
* this may break end-of-block comment when singular quotes are
|
||||
* in a comment. If we don't interpret quotes in a comment,
|
||||
|
@ -1194,15 +1136,17 @@ int rgetc(FILE *fp)
|
|||
}
|
||||
|
||||
/* implement backslashed quotes for 2.4 */
|
||||
if(!xa23 && c=='\\') quotebs=1; else quotebs=0;
|
||||
if (!xa23 && c == '\\')
|
||||
quotebs = 1;
|
||||
else
|
||||
quotebs = 0;
|
||||
|
||||
} else {
|
||||
/* in comment */
|
||||
|
||||
/* check for end of comment */
|
||||
/* note: for xa2.3, incomment only set true if not quoted, and quote not changed in comment */
|
||||
if((!inquote || !xa23) && (c=='*'))
|
||||
{
|
||||
if ((!inquote || !xa23) && (c == '*')) {
|
||||
if ((d = getc(fp)) != '/') {
|
||||
d_isvalid = 1;
|
||||
} else {
|
||||
|
@ -1232,8 +1176,7 @@ int rgetc(FILE *fp)
|
|||
* the rlen out parameter is just convenience, so that
|
||||
* a further strlen() can be saved
|
||||
*/
|
||||
int fgetline(char *t, int len, int *rlen, FILE *fp)
|
||||
{
|
||||
int fgetline(char *t, int len, int *rlen, FILE *fp) {
|
||||
static int c, i;
|
||||
|
||||
i = 0;
|
||||
|
@ -1241,8 +1184,7 @@ int fgetline(char *t, int len, int *rlen, FILE *fp)
|
|||
do {
|
||||
c = rgetc(fp);
|
||||
|
||||
if(c==EOF || c=='\n')
|
||||
{
|
||||
if (c == EOF || c == '\n') {
|
||||
t[i] = '\0';
|
||||
break;
|
||||
}
|
||||
|
|
50
xa/src/xar.c
50
xa/src/xar.c
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* Relocation module (for relocatable objects)
|
||||
*
|
||||
|
@ -50,12 +50,13 @@ printf("set relocation @$%04x, l=%d, afl=%04x, segment=%d, label=%d\n",
|
|||
pc, l, afl,segment, label);
|
||||
#endif
|
||||
if (((afl & A_FMASK) == (SEG_UNDEF << 8))
|
||||
|| ((afl & A_FMASK) == (SEG_UNDEFZP<<8))
|
||||
) {
|
||||
|| ((afl & A_FMASK) == (SEG_UNDEFZP << 8))) {
|
||||
label = u_label(label); /* set label as undefined */
|
||||
}
|
||||
if(segment==SEG_TEXT) return rt_set(pc,afl,l,label);
|
||||
if(segment==SEG_DATA) return rd_set(pc,afl,l,label);
|
||||
if (segment == SEG_TEXT)
|
||||
return rt_set(pc, afl, l, label);
|
||||
if (segment == SEG_DATA)
|
||||
return rd_set(pc, afl, l, label);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -76,7 +77,8 @@ void r_mode(int m) {
|
|||
int rt_set(int pc, int afl, int l, int lab) {
|
||||
int p, pp;
|
||||
|
||||
if(!rmode) return 0;
|
||||
if (!rmode)
|
||||
return 0;
|
||||
|
||||
/*printf("set relocation @$%04x, l=%d, afl=%04x\n",pc, l, afl);*/
|
||||
|
||||
|
@ -86,8 +88,7 @@ int rt_set(int pc, int afl, int l, int lab) {
|
|||
}
|
||||
if (l == 1 && ((afl & A_MASK) == A_ADR)) {
|
||||
if (((afl & A_FMASK) != (SEG_ZERO << 8))
|
||||
&& ((afl & A_FMASK) != (SEG_UNDEFZP<<8))
|
||||
) {
|
||||
&& ((afl & A_FMASK) != (SEG_UNDEFZP << 8))) {
|
||||
/*printf("afl=%04x\n",afl);*/
|
||||
errout(W_ADRRELOC);
|
||||
}
|
||||
|
@ -97,7 +98,8 @@ int rt_set(int pc, int afl, int l, int lab) {
|
|||
|
||||
if (afile->rt.nlist >= afile->rt.mlist) {
|
||||
afile->rt.mlist += 500;
|
||||
afile->rt.rlist=realloc(afile->rt.rlist, afile->rt.mlist*sizeof(relocateInfo));
|
||||
afile->rt.rlist = realloc(afile->rt.rlist,
|
||||
afile->rt.mlist * sizeof(relocateInfo));
|
||||
}
|
||||
if (!afile->rt.rlist) {
|
||||
fprintf(stderr, "Oops: no memory for relocation table!\n");
|
||||
|
@ -113,7 +115,8 @@ int rt_set(int pc, int afl, int l, int lab) {
|
|||
if (afile->rt.first < 0) {
|
||||
afile->rt.first = afile->rt.nlist;
|
||||
} else {
|
||||
p=afile->rt.first; pp=-1;
|
||||
p = afile->rt.first;
|
||||
pp = -1;
|
||||
while (afile->rt.rlist[p].adr < pc && afile->rt.rlist[p].next >= 0) {
|
||||
pp = p;
|
||||
p = afile->rt.rlist[p].next;
|
||||
|
@ -124,8 +127,7 @@ printf("endloop: p=%d(%04x), pp=%d(%04x), nlist=%d(%04x)\n",
|
|||
*/
|
||||
if (afile->rt.rlist[p].next < 0 && afile->rt.rlist[p].adr < pc) {
|
||||
afile->rt.rlist[p].next = afile->rt.nlist;
|
||||
} else
|
||||
if(pp==-1) {
|
||||
} else if (pp == -1) {
|
||||
afile->rt.rlist[afile->rt.nlist].next = afile->rt.first;
|
||||
afile->rt.first = afile->rt.nlist;
|
||||
} else {
|
||||
|
@ -146,7 +148,8 @@ int rt_write(FILE *fp, int pc) {
|
|||
pc2 = afile->rt.rlist[p].adr;
|
||||
afl = afile->rt.rlist[p].afl;
|
||||
/* hack to switch undef and abs flag from internal to file format */
|
||||
if( ((afl & A_FMASK)>>8) < SEG_TEXT) afl^=0x100;
|
||||
if (((afl & A_FMASK) >> 8) < SEG_TEXT)
|
||||
afl ^= 0x100;
|
||||
/*printf("rt_write: pc=%04x, pc2=%04x, afl=%x\n",pc,pc2,afl);*/
|
||||
if ((pc2 - pc) < 0) {
|
||||
fprintf(stderr, "Oops, negative offset!\n");
|
||||
|
@ -168,7 +171,8 @@ int rt_write(FILE *fp, int pc) {
|
|||
fputc((afile->rt.rlist[p].lab >> 8) & 255, fp);
|
||||
}
|
||||
}
|
||||
if((afl&A_MASK)==A_HIGH) fputc(afl&255,fp);
|
||||
if ((afl & A_MASK) == A_HIGH)
|
||||
fputc(afl & 255, fp);
|
||||
}
|
||||
p = afile->rt.rlist[p].next;
|
||||
}
|
||||
|
@ -182,7 +186,6 @@ int rt_write(FILE *fp, int pc) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void seg_start(int fmode, int t_base, int d_base, int b_base, int z_base,
|
||||
int slen, int relmode) {
|
||||
afile->fmode = fmode;
|
||||
|
@ -198,7 +201,6 @@ void seg_start(int fmode, int t_base, int d_base, int b_base, int z_base,
|
|||
pc[SEG_ABS] = pc[SEG_TEXT];
|
||||
}
|
||||
|
||||
|
||||
File* alloc_file(void) {
|
||||
File *afile;
|
||||
int i;
|
||||
|
@ -217,21 +219,25 @@ File *alloc_file(void) {
|
|||
afile->mn.tmpz = 0;
|
||||
afile->mn.tmpe = 0;
|
||||
|
||||
afile->ud.ulist = NULL; afile->ud.un = afile->ud.um = 0;
|
||||
afile->rt.rlist = NULL; afile->rt.first = -1;
|
||||
afile->ud.ulist = NULL;
|
||||
afile->ud.un = afile->ud.um = 0;
|
||||
afile->rt.rlist = NULL;
|
||||
afile->rt.first = -1;
|
||||
afile->rt.mlist = afile->rt.nlist = 0;
|
||||
afile->rd.rlist = NULL; afile->rd.first = -1;
|
||||
afile->rd.rlist = NULL;
|
||||
afile->rd.first = -1;
|
||||
afile->rd.mlist = afile->rd.nlist = 0;
|
||||
afile->fo.olist = NULL;
|
||||
afile->fo.mlist = afile->fo.nlist = 0;
|
||||
|
||||
for(i=0;i<256;i++) afile->la.hashindex[i]=0;
|
||||
for (i = 0; i < 256; i++)
|
||||
afile->la.hashindex[i] = 0;
|
||||
afile->la.lt = NULL;
|
||||
afile->la.lti = 0;
|
||||
afile->la.ltm = 0;
|
||||
|
||||
afile->len[SEG_TEXT] = afile->len[SEG_DATA] =
|
||||
afile->len[SEG_BSS] = afile->len[SEG_ZERO] = 0;
|
||||
afile->len[SEG_TEXT] = afile->len[SEG_DATA] = afile->len[SEG_BSS] =
|
||||
afile->len[SEG_ZERO] = 0;
|
||||
|
||||
return afile;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (a.fachat@physik.tu-chemnitz.de)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -44,14 +44,16 @@ int rd_set(int pc, int afl, int l, int lab) {
|
|||
/*printf("Warning: byte relocation in word value at PC=$%04x!\n",pc);*/
|
||||
}
|
||||
if (l == 1 && ((afl & A_MASK) == A_ADR)) {
|
||||
if((afl & A_FMASK) != (SEG_ZERO<<8)) errout(W_ADRRELOC);
|
||||
if ((afl & A_FMASK) != (SEG_ZERO << 8))
|
||||
errout(W_ADRRELOC);
|
||||
/*printf("Warning: cutting address relocation in byte value at PC=$%04x!\n",pc);*/
|
||||
afl = (afl & (~A_MASK)) | A_LOW;
|
||||
}
|
||||
|
||||
if (afile->rd.nlist >= afile->rd.mlist) {
|
||||
afile->rd.mlist += 500;
|
||||
afile->rd.rlist=realloc(afile->rd.rlist, afile->rd.mlist*sizeof(relocateInfo));
|
||||
afile->rd.rlist = realloc(afile->rd.rlist,
|
||||
afile->rd.mlist * sizeof(relocateInfo));
|
||||
}
|
||||
if (!afile->rd.rlist) {
|
||||
fprintf(stderr, "Oops: no memory for relocation table!\n");
|
||||
|
@ -67,7 +69,8 @@ int rd_set(int pc, int afl, int l, int lab) {
|
|||
if (afile->rd.first < 0) {
|
||||
afile->rd.first = afile->rd.nlist;
|
||||
} else {
|
||||
p=afile->rd.first; pp=-1;
|
||||
p = afile->rd.first;
|
||||
pp = -1;
|
||||
while (afile->rd.rlist[p].adr < pc && afile->rd.rlist[p].next >= 0) {
|
||||
pp = p;
|
||||
p = afile->rd.rlist[p].next;
|
||||
|
@ -78,8 +81,7 @@ printf("endloop: p=%d(%04x), pp=%d(%04x), nlist=%d(%04x)\n",
|
|||
*/
|
||||
if (afile->rd.rlist[p].next < 0 && afile->rd.rlist[p].adr < pc) {
|
||||
afile->rd.rlist[p].next = afile->rd.nlist;
|
||||
} else
|
||||
if(pp==-1) {
|
||||
} else if (pp == -1) {
|
||||
afile->rd.rlist[afile->rd.nlist].next = afile->rd.first;
|
||||
afile->rd.first = afile->rd.nlist;
|
||||
} else {
|
||||
|
@ -101,7 +103,8 @@ int rd_write(FILE *fp, int pc) {
|
|||
afl = afile->rd.rlist[p].afl;
|
||||
/*printf("rd_write: pc=%04x, pc2=%04x, afl=%x\n",pc,pc2,afl);*/
|
||||
/* hack to switch undef and abs flag from internal to file format */
|
||||
if( ((afl & A_FMASK)>>8) < SEG_TEXT) afl^=0x100;
|
||||
if (((afl & A_FMASK) >> 8) < SEG_TEXT)
|
||||
afl ^= 0x100;
|
||||
if ((pc2 - pc) < 0) {
|
||||
fprintf(stderr, "Oops, negative offset!\n");
|
||||
} else {
|
||||
|
@ -122,7 +125,8 @@ int rd_write(FILE *fp, int pc) {
|
|||
fputc((afile->rd.rlist[p].lab >> 8) & 255, fp);
|
||||
}
|
||||
}
|
||||
if((afl&A_MASK)==A_HIGH) fputc(afl&255,fp);
|
||||
if ((afl & A_MASK) == A_HIGH)
|
||||
fputc(afl & 255, fp);
|
||||
}
|
||||
p = afile->rd.rlist[p].next;
|
||||
}
|
||||
|
|
848
xa/src/xat.c
848
xa/src/xat.c
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
/* xa65 - 65xx/65816 cross-assembler and utility suite
|
||||
*
|
||||
* Copyright (C) 1989-1997 André Fachat (fachat@web.de)
|
||||
* Copyright (C) 1989-1997 Andr<EFBFBD> Fachat (fachat@web.de)
|
||||
*
|
||||
* Undefined label tracking module (also see xal.c)
|
||||
*
|
||||
|
@ -36,11 +36,13 @@ printf("u_label: %d\n",labnr);
|
|||
#endif
|
||||
if (!afile->ud.ulist) {
|
||||
afile->ud.ulist = malloc(200 * sizeof(int));
|
||||
if(afile->ud.ulist) afile->ud.um=200;
|
||||
if (afile->ud.ulist)
|
||||
afile->ud.um = 200;
|
||||
}
|
||||
|
||||
for (i = 0; i < afile->ud.un; i++) {
|
||||
if(afile->ud.ulist[i] == labnr) return i;
|
||||
if (afile->ud.ulist[i] == labnr)
|
||||
return i;
|
||||
}
|
||||
if (afile->ud.un >= afile->ud.um) {
|
||||
afile->ud.um *= 1.5;
|
||||
|
|
Loading…
Reference in New Issue
Block a user