Added .eqs and .ofs directives.

This commit is contained in:
Eric Smith 2003-09-16 12:00:00 +00:00
parent d15aed1646
commit b3573b6351
4 changed files with 78 additions and 32 deletions

6
dis.h
View File

@ -1,7 +1,7 @@
/*
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
*
* $Id: dis.h,v 1.5 2003/09/15 21:46:32 eric Exp $
* $Id: dis.h,v 1.6 2003/09/16 12:00:00 eric Exp $
* Copyright 2000-2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -40,6 +40,7 @@ extern int base_address, vector_address;
extern int asmout;
extern unsigned char f[];
extern unsigned char d[];
extern long offset[];
#define getword(x) (d[x] + (d[x+1] << 8))
#define getbyte(x) (d[x])
@ -53,6 +54,7 @@ extern unsigned char d[];
#define NAMED 0x10 /* Has a name */
#define TDONE 0x20 /* Has been traced */
#define ISOP 0x40 /* Is a valid instruction opcode */
#define OFFSET 0x80 /* should be printed as an offset */
struct info {
char opn[4];
@ -111,6 +113,8 @@ char *get_name(addr_t loc);
#define TSTOP 262
#define TRTSTAB 263
#define TJTAB2 264
#define EQS 265
#define OFS 266
extern FILE *yyin, *yyout;
int lineno;

6
lex.l
View File

@ -1,7 +1,7 @@
/*
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
*
* $Id: lex.l,v 1.5 2003/09/15 21:49:46 eric Exp $
* $Id: lex.l,v 1.6 2003/09/16 12:00:00 eric Exp $
* Copyright 2001-2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -47,6 +47,10 @@ alphanum [0-9a-zA-Z_]
\.[Ee][Qq] { return EQ; }
\.[Ee][Qq][Ss] { return EQS; }
\.[Oo][Ff][Ss] { return OFS; }
\.[Ll][Ii] { return LI; }
\.[Tt][Rr][Aa][Cc][Ee] { return TSTART; }

68
main.c
View File

@ -1,7 +1,7 @@
/*
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
*
* $Id: main.c,v 1.7 2003/09/15 21:46:32 eric Exp $
* $Id: main.c,v 1.8 2003/09/16 12:00:00 eric Exp $
* Copyright 2000-2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -54,6 +54,7 @@ VALUE token;
unsigned char d[0x10000]; /* The data */
unsigned char f[0x10000]; /* Flags for memory usage */
long offset [0x10000]; /* label offset */
#define RUNLOC 0x2e0
@ -300,7 +301,8 @@ int main (int argc, char *argv[])
void get_predef (void)
{
int loc;
long loc, loc2;
int i;
int size;
char *name;
@ -369,18 +371,60 @@ void get_predef (void)
break;
case NAME:
name = token.sval;
if (yylex() != EQ)
crash("name can only be used with equate in defines file");
if (yylex() != NUMBER)
crash("EQ operand must be a number");
loc = token.ival;
if (loc > 0x10000 || loc < 0)
crash("Number out of range");
f[loc] |= NAMED;
save_name(loc, name);
switch (yylex ())
{
case EQ:
if (yylex() != NUMBER)
crash("EQ operand must be a number");
loc = token.ival;
if (loc > 0x10000 || loc < 0)
crash("Number out of range");
f[loc] |= NAMED;
save_name(loc, name);
break;
case EQS:
if (yylex() != NUMBER)
crash("EQS operand must be a number");
loc = token.ival;
if (loc > 0x10000 || loc < 0)
crash("Number out of range");
if (yylex() != ',')
crash(".eqs needs a comma");
if (yylex() != NUMBER)
crash("EQS operand must be a number");
size = token.ival;
f[loc] |= NAMED;
save_name(loc, name);
for (i = 1; i < size; i++)
{
f [loc + i] |= OFFSET;
offset [loc + i] = -i;
}
break;
default:
crash("name can only be used with equate in defines file");
break;
}
while (yylex() != '\n')
;
;
break;
case OFS:
if (yylex() != NUMBER)
crash("EQ operand must be a number");
loc = token.ival;
if (loc > 0x10000 || loc < 0)
crash("Number out of range");
if (yylex() != ',')
crash(".ofs needs a comma");
if (yylex() != NUMBER)
crash("EQ operand must be a number");
loc2 = token.ival;
if (loc2 > 0x10000 || loc2 < 0)
crash("Number out of range");
/*$$$*/
f[loc] |= OFFSET;
offset[loc] = loc2 - loc;
break;
default:
crash("Invalid line in predef file");
}

30
print.c
View File

@ -1,7 +1,7 @@
/*
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
*
* $Id: print.c,v 1.7 2003/09/15 21:46:32 eric Exp $
* $Id: print.c,v 1.8 2003/09/16 12:00:00 eric Exp $
* Copyright 2000-2003 Eric Smith <eric@brouhaha.com>
*
* This program is free software; you can redistribute it and/or modify
@ -24,6 +24,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
@ -35,13 +36,6 @@ char *strcpy();
char *strcat();
static int has_offset (addr_t i)
{
return ((i > 0) && (! (f [i] & NAMED)) &&
((f [i-1] & (NAMED | DREF)) == (NAMED | DREF)));
}
static char *lname (addr_t i, int offset_ok)
{
static char buf[20];
@ -49,9 +43,11 @@ static char *lname (addr_t i, int offset_ok)
if (f[i] & NAMED)
return(get_name(i));
if (offset_ok && has_offset (i)) {
(void)strcpy(buf, get_name(i-1));
(void)strcat(buf, "+1");
if (f[i] & OFFSET) {
(void)strcpy(buf, get_name(i+offset[i]));
sprintf (buf + strlen (buf), "%c%ld",
(offset [i] <= 0) ? '+' : '-',
labs (offset [i]));
return (buf);
}
if (f[i] & SREF)
@ -79,7 +75,8 @@ static char *lname (addr_t i, int offset_ok)
static int print_label (addr_t i)
{
if (f[i] & (NAMED | JREF | SREF | DREF))
if ((f[i] & (NAMED | JREF | SREF | DREF)) &&
! (f [i] & OFFSET))
{
printf("%s", lname(i, 0));
return (1);
@ -107,11 +104,8 @@ void dumpitout (void)
printf("%04x ",i);
print_bytes(i);
}
if (! has_offset (i))
{
if (print_label(i))
printf (":");
}
if (print_label(i))
printf (":");
printf ("\t");
if (f[i] & ISOP)
i += print_inst(i);
@ -122,7 +116,7 @@ void dumpitout (void)
}
else
{
if ((! has_offset (i)) && print_label (i))
if (print_label (i))
{
if (i <= 0xff)
printf ("\t.equ\t$%02x\n", i);