1
0
mirror of https://github.com/brouhaha/dis6502.git synced 2024-11-27 07:50:58 +00:00

Add jtab.

This commit is contained in:
Eric Smith 2018-03-11 12:02:12 -06:00
parent 7493ac11e0
commit 2857fc340e
3 changed files with 42 additions and 2 deletions

5
dis.h
View File

@ -119,8 +119,9 @@ char *get_name(addr_t loc);
#define TSTOP 262
#define TRTSTAB 263
#define TJTAB2 264
#define EQS 265
#define OFS 266
#define TJTAB 265
#define EQS 266
#define OFS 267
extern FILE *yyin, *yyout;
int lineno;

2
lex.l
View File

@ -62,6 +62,8 @@ alphanum [0-9a-zA-Z_]
\.[Jj][Tt][Aa][Bb]2 { return TJTAB2; }
\.[Jj][Tt][Aa][Bb] { return TJTAB; }
{digit}+ {
(void)sscanf(yytext, "%d", &token.ival);
return NUMBER;

37
main.c
View File

@ -45,6 +45,12 @@ int rtstab_addr [RTSTAB_MAX]; /* .rtstab directive */
int rtstab_size [RTSTAB_MAX];
int rtstab_count = 0;
#define JTAB_MAX 50
int jtab_addr [JTAB_MAX]; /* .jtab directive */
int jtab_size [JTAB_MAX];
int jtab_count = 0;
#define JTAB2_MAX 50
int jtab2_addr_low [JTAB2_MAX]; /* .jtab2 directive */
@ -249,6 +255,22 @@ void do_rtstab (void)
}
}
void do_jtab (void)
{
for (int i = 0; i < jtab_count; i++)
{
int loc = jtab_addr [i];
for (int j = 0; j < jtab_size [i]; j++)
{
char *trace_sym = (char *) malloc (6);
int code = d [loc] + (d [loc + 1] << 8);
sprintf (trace_sym, "T%04x", code);
start_trace (code, trace_sym);
loc += 2;
}
}
}
void do_jtab2 (void)
{
for (int i = 0; i < jtab2_count; i++)
@ -302,6 +324,7 @@ int main (int argc, char *argv[])
do_ptrace ();
do_rtstab ();
do_jtab ();
do_jtab2 ();
trace_all ();
@ -340,6 +363,20 @@ void get_predef (void)
rtstab_addr [rtstab_count] = loc;
rtstab_size [rtstab_count++] = size;
break;
case TJTAB:
if (yylex() != NUMBER)
crash(".jtab needs an address operand");
loc = token.ival;
if (loc > 0x10000 || loc < 0)
crash("Number out of range");
if (yylex() != ',')
crash(".jtab needs a comma");
if (yylex() != NUMBER)
crash(".jtab needs a comma");
size = token.ival;
jtab_addr [jtab_count] = loc;
jtab_size [jtab_count++] = size;
break;
case TJTAB2:
if (yylex() != NUMBER)
crash(".jtab2 needs a number operand");