Added more commands
This commit is contained in:
parent
1d5d33a613
commit
ee40bed389
1 changed files with 62 additions and 6 deletions
|
@ -1,5 +1,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h> // for the uintx_t's
|
#include <stdint.h> // 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 {
|
typedef struct ConditionCodes {
|
||||||
|
@ -73,20 +78,58 @@ int emulate8080(State8080* state) {
|
||||||
uint32_t res = h1 + bc;
|
uint32_t res = h1 + bc;
|
||||||
state->h = (res & 0xff) >> 8;
|
state->h = (res & 0xff) >> 8;
|
||||||
state->l = res & 0xff;
|
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;
|
break;
|
||||||
case 0x0e: // MVI C, byte
|
case 0x0e: // MVI C, byte
|
||||||
state->c = opcode[1];
|
state->c = opcode[1];
|
||||||
state->pc += 1;
|
state->pc += 1;
|
||||||
break;
|
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
|
case 0x11: // LXI D, word
|
||||||
state->d = opcode[2];
|
state->d = opcode[2];
|
||||||
state->e = opcode[1];
|
state->e = opcode[1];
|
||||||
state->pc += 2;
|
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
|
case 0x21: // LXI H, word
|
||||||
state->h = opcode[2];
|
state->h = opcode[2];
|
||||||
state->l = opcode[1];
|
state->l = opcode[1];
|
||||||
state->pc += 2;
|
state->pc += 2;
|
||||||
|
case 0x23: // INX H
|
||||||
|
state->l++;
|
||||||
|
if (state->l == 0) {
|
||||||
|
state->h++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 0x26: // MVI H, byte
|
case 0x26: // MVI H, byte
|
||||||
state->h = opcode[1];
|
state->h = opcode[1];
|
||||||
state->pc += 1;
|
state->pc += 1;
|
||||||
|
@ -186,11 +229,7 @@ int emulate8080(State8080* state) {
|
||||||
state->pc++;
|
state->pc++;
|
||||||
break;
|
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
|
case 0x1f: // RAR
|
||||||
uint8_t x = state->a;
|
uint8_t x = state->a;
|
||||||
|
@ -198,6 +237,23 @@ int emulate8080(State8080* state) {
|
||||||
state->cc.cy = (1 == (x & 1));
|
state->cc.cy = (1 == (x & 1));
|
||||||
break;
|
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
|
case 0xfe: // CPI byte
|
||||||
uint8_t x = state->a - opcode[1];
|
uint8_t x = state->a - opcode[1];
|
||||||
state->cc.z = (x == 0);
|
state->cc.z = (x == 0);
|
||||||
|
|
Loading…
Reference in a new issue