From e16a879527302502638b8185cb92c3fb9a029d4e Mon Sep 17 00:00:00 2001 From: g1n Date: Thu, 14 Oct 2021 14:18:37 +0300 Subject: [PATCH] Add 6502 TXA instruction --- src/6502.c | 5 +++++ src/6502.h | 14 ++++++++++++++ src/Makefile | 2 +- src/main.c | 6 ++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/6502.c b/src/6502.c index eff29a2..c8b1d0f 100644 --- a/src/6502.c +++ b/src/6502.c @@ -1,6 +1,10 @@ #include #include "6502.h" +void txa(FILE *outfile) { + fwrite(TXA, 1, 1, outfile); +} + void inx(FILE *outfile) { fwrite(INX, 1, 1, outfile); } @@ -12,3 +16,4 @@ void iny(FILE *outfile) { void nop(FILE *outfile) { fwrite(NOP, 1, 1, outfile); } + diff --git a/src/6502.h b/src/6502.h index edf1f67..1ef1b21 100644 --- a/src/6502.h +++ b/src/6502.h @@ -1,9 +1,23 @@ +#ifndef _6502_H +#define _6502_H + +#define TAX "\xAA" +#define TAY "\xA8" +#define TSX "\xBA" +#define TXA "\x8A" +#define TXS "\x9A" +#define TYA "\x98" + #define INX "\xE8" #define INY "\xC8" #define NOP "\xEA" +void txa(FILE *outfile); + void inx(FILE *outfile); void iny(FILE *outfile); void nop(FILE *outfile); + +#endif diff --git a/src/Makefile b/src/Makefile index d518cee..d342a24 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,6 +13,6 @@ all: main main: $(CC) $(CFLAGS) $(SRCFILES) -o $(OBJFILES) test: - ./gasm ../tests/test.asm ../tests/test.bin + ./gasm ../tests/test.asm -o ../tests/test.bin xxd ../tests/test.bin diff --git a/src/main.c b/src/main.c index 965235a..f4d2ce7 100644 --- a/src/main.c +++ b/src/main.c @@ -39,9 +39,11 @@ void parser(char lexed_buf[512][128][128], FILE *outfile) { // outfile is needed inx(outfile); } else if (!strcmp(lexed_buf[i][j], "INY")) { iny(outfile); + } else if (!strcmp(lexed_buf[i][j], "TXA")) { + txa(outfile); } else { - printf("Unrecognized command: %s\n", lexed_buf[i][j]); - break; + printf("Unrecognized command: %s\n", lexed_buf[i][j]); + break; } } }