From b27a51bc0460bfba2afe29454d655af640248d1b Mon Sep 17 00:00:00 2001 From: g1n Date: Fri, 15 Oct 2021 14:39:52 +0300 Subject: [PATCH] Add 6502 DEX and DEY instructions --- src/6502.c | 9 +++++++++ src/6502.h | 4 ++++ src/main.c | 4 ++++ tests/test.asm | 11 +++-------- tests/test.bin | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/6502.c b/src/6502.c index d0deecf..c85b182 100644 --- a/src/6502.c +++ b/src/6502.c @@ -33,6 +33,15 @@ void iny(FILE *outfile) { fwrite(INY, 1, 1, outfile); } +void dex(FILE *outfile) { + fwrite(DEX, 1, 1, outfile); +} + +void dey(FILE *outfile) { + fwrite(DEY, 1, 1, outfile); +} + + void nop(FILE *outfile) { fwrite(NOP, 1, 1, outfile); } diff --git a/src/6502.h b/src/6502.h index ce3fdd8..33bdc19 100644 --- a/src/6502.h +++ b/src/6502.h @@ -10,6 +10,8 @@ #define INX "\xE8" #define INY "\xC8" +#define DEX "\xCA" +#define DEY "\x88" #define NOP "\xEA" @@ -22,6 +24,8 @@ void tya(FILE *outfile); void inx(FILE *outfile); void iny(FILE *outfile); +void dex(FILE *outfile); +void dey(FILE *outfile); void nop(FILE *outfile); diff --git a/src/main.c b/src/main.c index 9ffecf3..d6a0487 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,10 @@ 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], "DEX")) { + dex(outfile); + } else if (!strcmp(lexed_buf[i][j], "DEY")) { + dey(outfile); } else if (!strcmp(lexed_buf[i][j], "TAX")) { tax(outfile); } else if (!strcmp(lexed_buf[i][j], "TAY")) { diff --git a/tests/test.asm b/tests/test.asm index aed58e6..4e3ecd6 100644 --- a/tests/test.asm +++ b/tests/test.asm @@ -1,14 +1,9 @@ INY INY -INX -TXA INY -TAX -INX -INX -TAY +DEY INX INX INX -INY -INY +DEX +DEX diff --git a/tests/test.bin b/tests/test.bin index e8bd143..52667cf 100644 --- a/tests/test.bin +++ b/tests/test.bin @@ -1 +1 @@ -ÈÈèŠÈªèè¨èèèÈÈ \ No newline at end of file +ÈÈȈèèèÊÊ \ No newline at end of file