mirror of
https://github.com/brouhaha/dis6502.git
synced 2025-02-17 07:32:46 +00:00
Added .eqs and .ofs directives.
This commit is contained in:
parent
d15aed1646
commit
b3573b6351
6
dis.h
6
dis.h
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
|
* 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>
|
* Copyright 2000-2003 Eric Smith <eric@brouhaha.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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 int asmout;
|
||||||
extern unsigned char f[];
|
extern unsigned char f[];
|
||||||
extern unsigned char d[];
|
extern unsigned char d[];
|
||||||
|
extern long offset[];
|
||||||
|
|
||||||
#define getword(x) (d[x] + (d[x+1] << 8))
|
#define getword(x) (d[x] + (d[x+1] << 8))
|
||||||
#define getbyte(x) (d[x])
|
#define getbyte(x) (d[x])
|
||||||
@ -53,6 +54,7 @@ extern unsigned char d[];
|
|||||||
#define NAMED 0x10 /* Has a name */
|
#define NAMED 0x10 /* Has a name */
|
||||||
#define TDONE 0x20 /* Has been traced */
|
#define TDONE 0x20 /* Has been traced */
|
||||||
#define ISOP 0x40 /* Is a valid instruction opcode */
|
#define ISOP 0x40 /* Is a valid instruction opcode */
|
||||||
|
#define OFFSET 0x80 /* should be printed as an offset */
|
||||||
|
|
||||||
struct info {
|
struct info {
|
||||||
char opn[4];
|
char opn[4];
|
||||||
@ -111,6 +113,8 @@ char *get_name(addr_t loc);
|
|||||||
#define TSTOP 262
|
#define TSTOP 262
|
||||||
#define TRTSTAB 263
|
#define TRTSTAB 263
|
||||||
#define TJTAB2 264
|
#define TJTAB2 264
|
||||||
|
#define EQS 265
|
||||||
|
#define OFS 266
|
||||||
|
|
||||||
extern FILE *yyin, *yyout;
|
extern FILE *yyin, *yyout;
|
||||||
int lineno;
|
int lineno;
|
||||||
|
6
lex.l
6
lex.l
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
|
* 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>
|
* Copyright 2001-2003 Eric Smith <eric@brouhaha.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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] { return EQ; }
|
||||||
|
|
||||||
|
\.[Ee][Qq][Ss] { return EQS; }
|
||||||
|
|
||||||
|
\.[Oo][Ff][Ss] { return OFS; }
|
||||||
|
|
||||||
\.[Ll][Ii] { return LI; }
|
\.[Ll][Ii] { return LI; }
|
||||||
|
|
||||||
\.[Tt][Rr][Aa][Cc][Ee] { return TSTART; }
|
\.[Tt][Rr][Aa][Cc][Ee] { return TSTART; }
|
||||||
|
52
main.c
52
main.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
|
* 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>
|
* Copyright 2000-2003 Eric Smith <eric@brouhaha.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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 d[0x10000]; /* The data */
|
||||||
unsigned char f[0x10000]; /* Flags for memory usage */
|
unsigned char f[0x10000]; /* Flags for memory usage */
|
||||||
|
long offset [0x10000]; /* label offset */
|
||||||
|
|
||||||
|
|
||||||
#define RUNLOC 0x2e0
|
#define RUNLOC 0x2e0
|
||||||
@ -300,7 +301,8 @@ int main (int argc, char *argv[])
|
|||||||
|
|
||||||
void get_predef (void)
|
void get_predef (void)
|
||||||
{
|
{
|
||||||
int loc;
|
long loc, loc2;
|
||||||
|
int i;
|
||||||
int size;
|
int size;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
@ -369,8 +371,9 @@ void get_predef (void)
|
|||||||
break;
|
break;
|
||||||
case NAME:
|
case NAME:
|
||||||
name = token.sval;
|
name = token.sval;
|
||||||
if (yylex() != EQ)
|
switch (yylex ())
|
||||||
crash("name can only be used with equate in defines file");
|
{
|
||||||
|
case EQ:
|
||||||
if (yylex() != NUMBER)
|
if (yylex() != NUMBER)
|
||||||
crash("EQ operand must be a number");
|
crash("EQ operand must be a number");
|
||||||
loc = token.ival;
|
loc = token.ival;
|
||||||
@ -378,9 +381,50 @@ void get_predef (void)
|
|||||||
crash("Number out of range");
|
crash("Number out of range");
|
||||||
f[loc] |= NAMED;
|
f[loc] |= NAMED;
|
||||||
save_name(loc, name);
|
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')
|
while (yylex() != '\n')
|
||||||
;
|
;
|
||||||
break;
|
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:
|
default:
|
||||||
crash("Invalid line in predef file");
|
crash("Invalid line in predef file");
|
||||||
}
|
}
|
||||||
|
26
print.c
26
print.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* dis6502 by Robert Bond, Udi Finkelstein, and Eric Smith
|
* 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>
|
* Copyright 2000-2003 Eric Smith <eric@brouhaha.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -24,6 +24,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -35,13 +36,6 @@ char *strcpy();
|
|||||||
char *strcat();
|
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 *lname (addr_t i, int offset_ok)
|
||||||
{
|
{
|
||||||
static char buf[20];
|
static char buf[20];
|
||||||
@ -49,9 +43,11 @@ static char *lname (addr_t i, int offset_ok)
|
|||||||
|
|
||||||
if (f[i] & NAMED)
|
if (f[i] & NAMED)
|
||||||
return(get_name(i));
|
return(get_name(i));
|
||||||
if (offset_ok && has_offset (i)) {
|
if (f[i] & OFFSET) {
|
||||||
(void)strcpy(buf, get_name(i-1));
|
(void)strcpy(buf, get_name(i+offset[i]));
|
||||||
(void)strcat(buf, "+1");
|
sprintf (buf + strlen (buf), "%c%ld",
|
||||||
|
(offset [i] <= 0) ? '+' : '-',
|
||||||
|
labs (offset [i]));
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
if (f[i] & SREF)
|
if (f[i] & SREF)
|
||||||
@ -79,7 +75,8 @@ static char *lname (addr_t i, int offset_ok)
|
|||||||
|
|
||||||
static int print_label (addr_t i)
|
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));
|
printf("%s", lname(i, 0));
|
||||||
return (1);
|
return (1);
|
||||||
@ -107,11 +104,8 @@ void dumpitout (void)
|
|||||||
printf("%04x ",i);
|
printf("%04x ",i);
|
||||||
print_bytes(i);
|
print_bytes(i);
|
||||||
}
|
}
|
||||||
if (! has_offset (i))
|
|
||||||
{
|
|
||||||
if (print_label(i))
|
if (print_label(i))
|
||||||
printf (":");
|
printf (":");
|
||||||
}
|
|
||||||
printf ("\t");
|
printf ("\t");
|
||||||
if (f[i] & ISOP)
|
if (f[i] & ISOP)
|
||||||
i += print_inst(i);
|
i += print_inst(i);
|
||||||
@ -122,7 +116,7 @@ void dumpitout (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((! has_offset (i)) && print_label (i))
|
if (print_label (i))
|
||||||
{
|
{
|
||||||
if (i <= 0xff)
|
if (i <= 0xff)
|
||||||
printf ("\t.equ\t$%02x\n", i);
|
printf ("\t.equ\t$%02x\n", i);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user