From ee40bed38924ae1592de7e2ce03f9b334f368f4b Mon Sep 17 00:00:00 2001 From: Luxdragon Date: Sat, 6 Jan 2024 22:23:36 +0100 Subject: [PATCH] Added more commands --- emulator_shell.c | 68 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/emulator_shell.c b/emulator_shell.c index 80b855c..65388f1 100644 --- a/emulator_shell.c +++ b/emulator_shell.c @@ -1,5 +1,10 @@ #include #include // for the uintx_t's +#include "disassembler.c" + +// gcc emulator_shell.c disassembler.c -o disassembler + +int disassemble8080(buffer* b, int pc); typedef struct ConditionCodes { @@ -73,20 +78,58 @@ int emulate8080(State8080* state) { uint32_t res = h1 + bc; state->h = (res & 0xff) >> 8; state->l = res & 0xff; - state->cc.cy = ((res > 0xffff) > 0); + state->cc.cy = ((res & 0xffff0000) > 0); + break; + + case 0x0d: // DCR C + uint8_t res = state->c - 1; + state->c = res; + state->cc.z = (res == 0); + state->cc.s = ((res & 0x80) != 0); + state->cc.p = parity(res, 8); break; case 0x0e: // MVI C, byte state->c = opcode[1]; state->pc += 1; break; + case 0x0f: // RRC + uint8_t x = state->a; + state->a = ((x & 1) << 7) | (x >> 1); + state->cc.cy = (1 == (x & 1)); + break; case 0x11: // LXI D, word state->d = opcode[2]; state->e = opcode[1]; state->pc += 2; + case 0x13: // INX D + state->e++; + if (state->e == 0) { + state->d++; + } + break; + case 0x19: // DAD D + uint32_t h1 = (state->h << 8) | state->l; + uint32_t de = (state->d << 8) | state->e; + uint32_t res = h1 + de; + state->h = (res & 0xff) >> 8; + state->l = res & 0xff; + state->cc.cy = ((res & 0xffff0000) != 0); + break; + case 0x1a: // LDAX D + uint16_t de = (state->d << 8) | state->e; + state->a = state->memory[de]; + break; + case 0x21: // LXI H, word state->h = opcode[2]; state->l = opcode[1]; state->pc += 2; + case 0x23: // INX H + state->l++; + if (state->l == 0) { + state->h++; + } + break; case 0x26: // MVI H, byte state->h = opcode[1]; state->pc += 1; @@ -186,11 +229,7 @@ int emulate8080(State8080* state) { state->pc++; break; - case 0x0f: // RRC - uint8_t x = state->a; - state->a = ((x & 1) << 7) | (x >> 1); - state->cc.cy = (1 == (x & 1)); - break; + case 0x1f: // RAR uint8_t x = state->a; @@ -198,6 +237,23 @@ int emulate8080(State8080* state) { state->cc.cy = (1 == (x & 1)); break; + case 0xf1: // POP PSW + state->a = state->memory[state->sp+1]; + uint8_t psw = state->memory[state->sp]; + state->cc.z = (0x01 == (psw & 0x01)); + state->cc.s = (0x02 == (psw & 0x02)); + state->cc.p = (0x04 == (psw & 0x04)); + state->cc.cy = (0x08 == (psw & 0x08)); + state->cc.ac = (0x10 == (psw & 0x10)); + state->sp += 2; + break; + + case 0xf5: // PUSH PSW + state->memory[state->sp-1] = state->a; + state->memory[state->sp-2] = (state->cc.z | (state->cc.s << 1) | (state->cc.p << 2) | (state->cc.cy << 3) | (state->cc.ac << 4)); + state->sp -= 2; + break; + case 0xfe: // CPI byte uint8_t x = state->a - opcode[1]; state->cc.z = (x == 0);