8080 Emulator can now do most opcodes
Still very buggy
This commit is contained in:
parent
215fcaf67b
commit
6b1c53dad5
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,4 +7,4 @@
|
||||
*.exe
|
||||
*.log
|
||||
*.sys
|
||||
utils/emul
|
||||
utils
|
||||
|
@ -96,6 +96,14 @@ uint16_t pop() {
|
||||
return v;
|
||||
}
|
||||
|
||||
void in(uint8_t port) {
|
||||
|
||||
}
|
||||
|
||||
void out(uint8_t port) {
|
||||
|
||||
}
|
||||
|
||||
int has_even_parity(uint8_t x){
|
||||
unsigned int count = 0, i, b = 1;
|
||||
|
||||
@ -115,19 +123,35 @@ void cpm_syscall(int number) {
|
||||
case 2:
|
||||
printf("%c", E);
|
||||
break;
|
||||
case 0x0C:
|
||||
H=0x02;
|
||||
L=0x00;
|
||||
break;;
|
||||
default:
|
||||
fprintf(stderr, "Fatal: Unhandled CP/M syscall %Xh\n", number);
|
||||
fprintf(stderr, "Fatal: Unhandled CP/M syscall C=%02Xh\n", number);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void handle_intr(int number) {
|
||||
switch(number) {
|
||||
|
||||
void call(uint16_t v) {
|
||||
switch(v) {
|
||||
case 0:
|
||||
exit(0);
|
||||
break;;
|
||||
case 5:
|
||||
cpm_syscall(C);
|
||||
break;;
|
||||
default:
|
||||
fprintf(stderr, "Fatal: Unhandled interrupt %Xh\n", number);
|
||||
exit(1);
|
||||
push(IP);
|
||||
IP=v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void interrupt(int number) {
|
||||
call(number << 3);
|
||||
}
|
||||
|
||||
#define add16c(a, b) \
|
||||
tmp = a + b; \
|
||||
flags.c = (tmp >> 16) & 1
|
||||
@ -361,6 +385,71 @@ void step() {
|
||||
case 0xBE: aritht(A, -, M); break;;
|
||||
case 0xBF: aritht(A, -, A); break;;
|
||||
|
||||
case 0xC0: if (!flags.z) IP=pop(); break;;
|
||||
case 0xC1: BC=pop(); break;;
|
||||
case 0xC2: if (!flags.z) IP=imm16(); break;;
|
||||
case 0xC3: IP=imm16(); break;;
|
||||
case 0xC4: if (!flags.z) call(imm16()); break;;
|
||||
case 0xC5: push(BC); break;;
|
||||
case 0xC6: arith(A, +, imm8()); break;;
|
||||
case 0xC7: interrupt(0); break;;
|
||||
|
||||
case 0xC8: if (flags.z) IP=pop(); break;;
|
||||
case 0xC9: IP=pop(); break;;
|
||||
case 0xCA: if (flags.z) IP=imm16(); break;;
|
||||
case 0xCC: if (flags.z) call(imm16()); break;;
|
||||
case 0xCD: call(imm16()); break;;
|
||||
case 0xCE: arith(A, +flags.c+, imm8()); break;;
|
||||
case 0xCF: interrupt(1); break;;
|
||||
|
||||
case 0xD0: if (!flags.c) IP=pop(); break;;
|
||||
case 0xD1: DE=pop(); break;;
|
||||
case 0xD2: if (!flags.c) IP=imm16(); break;;
|
||||
case 0xD3: out(imm8()); break;;
|
||||
case 0xD4: if (!flags.c) call(imm16()); break;;
|
||||
case 0xD5: push(DE); break;;
|
||||
case 0xD6: arith(A, -, imm8()); break;;
|
||||
case 0xD7: interrupt(2); break;;
|
||||
|
||||
case 0xD8: if (flags.c) IP=pop(); break;;
|
||||
case 0xDA: if (flags.c) IP=imm16(); break;;
|
||||
case 0xDB: in(imm8()); break;;
|
||||
case 0xDC: if (flags.c) call(imm16()); break;;
|
||||
case 0xDE: arith(A, -flags.c-, imm8()); break;;
|
||||
case 0xDF: interrupt(3); break;;
|
||||
|
||||
case 0xE0: if (!flags.p) IP=pop(); break;;
|
||||
case 0xE1: HL=pop(); break;;
|
||||
case 0xE2: if (!flags.p) IP=imm16(); break;;
|
||||
case 0xE3: tmp=HL; HL=pop(); push(tmp); break;;
|
||||
case 0xE4: if (!flags.p) call(imm16()); break;;
|
||||
case 0xE5: push(HL); break;;
|
||||
case 0xE6: arith(A, &, imm8()); break;;
|
||||
case 0xE7: interrupt(4); break;;
|
||||
|
||||
case 0xE8: if (flags.p) IP=pop(); break;;
|
||||
case 0xE9: IP=HL; break;;
|
||||
case 0xEA: if (flags.p) IP=imm16(); break;;
|
||||
case 0xEB: tmp=HL; HL=DE; DE=tmp;; break;;
|
||||
case 0xEC: if (flags.p) call(imm16()); break;;
|
||||
case 0xEE: arith(A, ^, imm8()); break;;
|
||||
case 0xEF: interrupt(5); break;;
|
||||
|
||||
case 0xF0: if (!flags.s) IP=pop(); break;;
|
||||
case 0xF1: regset.regp.psw=pop(); break;;
|
||||
case 0xF2: if (!flags.s) IP=imm16(); break;;
|
||||
case 0xF4: if (!flags.s) call(imm16()); break;;
|
||||
case 0xF5: push(regset.regp.psw); break;;
|
||||
case 0xF6: arith(A, |, imm8()); break;;
|
||||
case 0xF7: interrupt(6); break;;
|
||||
|
||||
case 0xF8: if (flags.s) IP=pop(); break;;
|
||||
case 0xF9: SP=HL; break;;
|
||||
case 0xFA: if (flags.s) IP=imm16(); break;;
|
||||
case 0xFC: if (flags.s) call(imm16()); break;;
|
||||
case 0xFE: aritht(A, -, imm8()); break;;
|
||||
case 0xFF: interrupt(7); break;;
|
||||
|
||||
default:
|
||||
IP--;
|
||||
dump();
|
||||
|
Loading…
Reference in New Issue
Block a user