Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dis.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/


#include <stddef.h>

extern bool sevenbit; /* if true, mask character data with 0x7f
to ignore MSB */

Expand Down Expand Up @@ -124,10 +126,10 @@ char *get_name(addr_t loc);
#define OFS 267

extern FILE *yyin, *yyout;
int lineno;
extern int lineno;

int yywrap(), yyerror();
char *emalloc();
void *emalloc (size_t n);

typedef union {
int ival;
Expand Down
15 changes: 7 additions & 8 deletions lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
%{
#undef ECHO
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "dis.h"
int lineno = 0;
char *strcpy();
%}

%option nounput
%option noinput nounput

digit [0-9]
hexdigit [0-9a-fA-F]
Expand Down Expand Up @@ -75,7 +75,7 @@ alphanum [0-9a-zA-Z_]
}

{alpha}{alphanum}* {
token.sval = emalloc((unsigned) strlen(yytext)+1);
token.sval = emalloc(strlen(yytext)+1);
(void)strcpy((char *)token.sval, (char *)yytext);
return NAME;
}
Expand All @@ -90,13 +90,12 @@ alphanum [0-9a-zA-Z_]

%%

char *
emalloc(n)
unsigned n;
void *
emalloc(size_t n)
{
char *ptr;
void *ptr;

if ((ptr = malloc(n)) == (char *) 0) {
if ((ptr = malloc(n)) == NULL) {
(void) fprintf(stderr,"out of core");
exit(1);
}
Expand Down
20 changes: 13 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void trace_inst (addr_t addr)
{
int opcode;
register struct info *ip;
int operand;
int operand = 0;
int istart;

for (;;)
Expand All @@ -116,7 +116,6 @@ void trace_inst (addr_t addr)
switch(ip->nb)
{
case 1:
operand = 0; /* only to avoid "may be used unitialized" warning */
break;
case 2:
operand = getbyte(addr);
Expand Down Expand Up @@ -232,7 +231,7 @@ void do_ptrace (void)
{
for (int i = 0; i<tstarti; i++)
{
char *trace_sym = (char *) malloc (6);
char *trace_sym = emalloc (6);
sprintf (trace_sym, "P%04x", tstart [i]);
start_trace(tstart[i], trace_sym);
}
Expand All @@ -246,7 +245,7 @@ void do_rtstab (void)
int loc = rtstab_addr [i];
for (int j = 0; j < rtstab_size [i]; j++)
{
char *trace_sym = (char *) malloc (6);
char *trace_sym = emalloc (6);
int code = d [loc] + (d [loc + 1] << 8) + 1;
sprintf (trace_sym, "T%04x", code);
start_trace (code, trace_sym);
Expand All @@ -262,7 +261,7 @@ void do_jtab (void)
int loc = jtab_addr [i];
for (int j = 0; j < jtab_size [i]; j++)
{
char *trace_sym = (char *) malloc (6);
char *trace_sym = emalloc (6);
int code = d [loc] + (d [loc + 1] << 8);
sprintf (trace_sym, "T%04x", code);
start_trace (code, trace_sym);
Expand All @@ -279,7 +278,7 @@ void do_jtab2 (void)
int loc_h = jtab2_addr_high [i];
for (int j = 0; j < jtab2_size [i]; j++)
{
char *trace_sym = (char *) malloc (6);
char *trace_sym = emalloc (6);
int code = d [loc_l + j] + (d [loc_h + j] << 8);
sprintf (trace_sym, "T%04x", code);
start_trace (code, trace_sym);
Expand Down Expand Up @@ -511,6 +510,8 @@ void loadboot (void)
if (fread((char *)&d[base_addr], 1, len, fp) != len)
crash("input too short");

fclose(fp);

for(int i = base_addr; len > 0; len--)
f[i++] |= LOADED;

Expand Down Expand Up @@ -544,6 +545,7 @@ void loadfile (void)
i = getword(RUNLOC);
start_trace(i, "**RUN**");
}
fclose(fp);
return;
}

Expand Down Expand Up @@ -608,6 +610,8 @@ void c64loadfile (void)
f[i++] |= LOADED;
}

fclose(fp);

start_trace(base_addr, "**C64BIN**");
}

Expand Down Expand Up @@ -637,6 +641,8 @@ void binaryloadfile (void)
f [i++] |= LOADED;
}

fclose(fp);

reset = vector_address - 4;
irq = vector_address - 2;
nmi = vector_address - 6;
Expand All @@ -647,7 +653,7 @@ void binaryloadfile (void)
{
for (int j = 0; j < entry_count; j++)
{
char *label = malloc(7);
char *label = emalloc (7);
sprintf (label, "e_%04x", entry_address[j]);
printf("label: %s\n", label);
start_trace (entry_address[j], label);
Expand Down
13 changes: 4 additions & 9 deletions print.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@

#include "dis.h"

char *strcpy();
char *strcat();


static char *lname (addr_t i, int offset_ok)
{
static char buf[20];
static char buf[40]; /* ~6-char label, +/-, long int */
char t;

if (f[i] & NAMED)
return(get_name(i));
if (f[i] & OFFSET) {
(void)strcpy(buf, get_name(i+offset[i]));
sprintf (buf + strlen (buf), "%c%ld",
sprintf (buf, "%s%c%ld",
get_name(i+offset[i]),
(offset [i] <= 0) ? '+' : '-',
labs (offset [i]));
return (buf);
Expand Down Expand Up @@ -168,7 +165,7 @@ int print_inst(addr_t addr)
{
int opcode;
register struct info *ip;
int operand;
int operand = 0;

opcode = getbyte(addr);
ip = &optbl[opcode];
Expand All @@ -179,8 +176,6 @@ int print_inst(addr_t addr)

switch(ip->nb) {
case 1:
operand = 0; /* only to avoid "may be used
unitialized" warning */
break;
case 2:
operand = getbyte(addr);
Expand Down
2 changes: 1 addition & 1 deletion ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void save_ref (addr_t refer, addr_t refee)
struct ref_chain *rc;
struct hashslot *hp;

rc = (struct ref_chain *)emalloc(sizeof(*rc));
rc = emalloc(sizeof(*rc));
rc->who = refer;
hp = hash(refee, 1);
rc->next = hp->ref;
Expand Down