~ndiddy/a65

213237dcb98d2202b4f5b3415bef7ea474e0cf1f — Nathan Misner 4 months ago d1ae049
added "incb" pseudo-op for including binary files
3 files changed, 52 insertions(+), 7 deletions(-)

M a65.c
M a65.h
M a65util.c
M a65.c => a65.c +42 -3
@@ 70,7 70,8 @@ static int done, ifsp, off;
int main(int argc, char **argv) {
    SCRATCH unsigned *o;

    printf("6502 Cross-Assembler (Portable) Ver 0.2n\n");
    /* printf("6502 Cross-Assembler (Portable) Ver 0.2n\n"); */
	printf("6502 Cross-Assembler (Portable), built %s\n", __DATE__);
    printf("Copyright (c) 1986 William C. Colley, III\n\n");

    while (--argc > 0) {


@@ 321,8 322,10 @@ do_zero_page:

static void pseudo_op() {
    SCRATCH char *s;
    SCRATCH unsigned *o, u;
    SCRATCH unsigned *o, result, u;
    SCRATCH SYMBOL *l;
	FILE *binfp;
	size_t size;

    o = obj;
    switch (opcod -> valu) {


@@ 424,7 427,25 @@ static void pseudo_op() {
		}
		break;

	case INCL:  
	case INCB:	/* include binary */
		do_label();
		if ((lex()->attr & TYPE) == STR) {
			binfp = fopen(token.sval, "rb");
			if (!binfp) {
				error('V');
			}
			else {
				while ((*o++ = fgetc(binfp)) != EOF) {
					bytes++;
				}
				fclose(binfp);
			}
		}
		else error('S');

		break;

	case INCL:	/* include source file */
		listhex = FALSE;  do_label();
		if ((lex() -> attr & TYPE) == STR) {
			if (++filesp == FILES) fatal_error(FLOFLOW);


@@ 458,6 479,24 @@ static void pseudo_op() {
		}
		break;

	case ALIGN:
		u = expr();
		if (forwd) error('P');
		else {
			/* round up pc to next multiple of align val */
			pc = address = ((pc + (u / 2)) / u) * u;
			if (pass == 2) bseek(pc);
		}
		do_label();
		break;

	case BASE:
		u = expr();
		if (forwd) error('P');
		else pc = address = u;
		do_label();
		break;

	case ORG:   
		u = expr();
		if (forwd) error('P');

M a65.h => a65.h +5 -2
@@ 81,7 81,9 @@ all modules of the cross-assembler.
/*  Line assembler (A65.C) pseudo-op opcode token values:		*/

typedef enum {
	DB = 1,
	ALIGN = 1,
	BASE,
	DB,
	DS,
	DW,
	ELSE,


@@ 89,6 91,7 @@ typedef enum {
	ENDI,
	EQU,
	IF,
	INCB,
	INCL,
	MSG,
	ORG,


@@ 212,7 215,7 @@ typedef struct _symbol SYMBOL;
typedef struct {
    unsigned attr;
    unsigned valu;
    char oname[5];
    char oname[6];
} OPCODE;

/*  Utility package (A65UTIL.C) hex file output routines:		*/

M a65util.c => a65util.c +5 -2
@@ 83,11 83,13 @@ SYMBOL *find_symbol(char *nam) {
/*  NULL if the opcode doesn't exist.					*/

OPCODE *find_code(char *nam) {
    static OPCODE opctbl[] = {
	static OPCODE opctbl[] = {
		{ TWOOP,			0x61,	"ADC"	},
		{ PSEUDO,			ALIGN,	"ALIGN"	},
		{ TWOOP,			0x21,	"AND"	},
		{ LOGOP,			0x06,	"ASL"	},
		{ INHOP,			0x0a,	"ASLA"	},
		{ PSEUDO,			BASE,	"BASE"	},
		{ RELBR,			0x90,	"BCC"	},
		{ RELBR,			0xb0,	"BCS"	},
		{ RELBR,			0xf0,	"BEQ"	},


@@ 118,6 120,7 @@ OPCODE *find_code(char *nam) {
		{ PSEUDO,			EQU,	"EQU"	},
		{ PSEUDO + ISIF,	IF,		"IF"	},
		{ INCOP,			0xe6,	"INC"	},
		{ PSEUDO,			INCB,	"INCB"	},
		{ PSEUDO,			INCL,	"INCL"	},
		{ INHOP,			0xe8,	"INX"	},
		{ INHOP,			0xc8,	"INY"	},


@@ 340,7 343,7 @@ void bputc(unsigned c) {
/*  seek forwards in the file. Seeking backwards will cause an error.	*/

void bseek(unsigned a) {
	unsigned cursor = addr + cnt;
	unsigned cursor = (addr + cnt) & 0xFFFF;
	unsigned difference;
	int i;