2017-06-04 20:38:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Auxiliary carry logic from https://github.com/begoon/i8080-core
|
|
|
|
|
2017-09-03 22:51:01 +00:00
|
|
|
#include <IntelProcessor.h>
|
|
|
|
#include <InputOutput.h>
|
2017-06-04 20:38:34 +00:00
|
|
|
|
|
|
|
namespace EightBit {
|
2017-06-11 08:45:34 +00:00
|
|
|
class Intel8080 : public IntelProcessor {
|
2017-06-04 20:38:34 +00:00
|
|
|
public:
|
2017-06-16 00:58:12 +00:00
|
|
|
enum StatusBits {
|
|
|
|
SF = Bit7,
|
|
|
|
ZF = Bit6,
|
|
|
|
AC = Bit4,
|
|
|
|
PF = Bit2,
|
|
|
|
CF = Bit0,
|
|
|
|
};
|
|
|
|
|
2017-09-06 12:22:23 +00:00
|
|
|
Intel8080(Bus& bus, InputOutput& ports);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
|
|
|
Signal<Intel8080> ExecutingInstruction;
|
|
|
|
|
2017-07-22 22:52:58 +00:00
|
|
|
bool isInterruptable() const;
|
|
|
|
int interrupt(uint8_t value);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-08-30 22:17:34 +00:00
|
|
|
virtual int execute(uint8_t opcode);
|
2017-06-04 20:38:34 +00:00
|
|
|
int step();
|
|
|
|
|
2017-07-24 21:00:49 +00:00
|
|
|
virtual register16_t& AF() override {
|
2017-07-25 17:56:43 +00:00
|
|
|
auto& f = af.low;
|
|
|
|
f = (f | Bit1) & ~(Bit5 | Bit3);
|
2017-07-24 21:00:49 +00:00
|
|
|
return af;
|
|
|
|
}
|
|
|
|
|
2017-08-30 22:17:34 +00:00
|
|
|
virtual register16_t& BC() override { return bc; }
|
|
|
|
virtual register16_t& DE() override { return de; }
|
|
|
|
virtual register16_t& HL() override { return hl; }
|
2017-07-24 21:00:49 +00:00
|
|
|
|
2017-06-04 20:38:34 +00:00
|
|
|
private:
|
2017-09-03 11:11:14 +00:00
|
|
|
bool m_interrupt;
|
2017-06-04 21:59:56 +00:00
|
|
|
InputOutput& m_ports;
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-06-16 00:58:12 +00:00
|
|
|
register16_t af;
|
2017-06-04 20:38:34 +00:00
|
|
|
register16_t bc;
|
|
|
|
register16_t de;
|
|
|
|
register16_t hl;
|
|
|
|
|
2017-08-06 16:06:48 +00:00
|
|
|
uint8_t R(int r) {
|
2017-07-24 21:00:49 +00:00
|
|
|
switch (r) {
|
|
|
|
case 0b000:
|
|
|
|
return B();
|
|
|
|
case 0b001:
|
|
|
|
return C();
|
|
|
|
case 0b010:
|
|
|
|
return D();
|
|
|
|
case 0b011:
|
|
|
|
return E();
|
|
|
|
case 0b100:
|
|
|
|
return H();
|
|
|
|
case 0b101:
|
|
|
|
return L();
|
|
|
|
case 0b110:
|
2017-08-28 17:52:48 +00:00
|
|
|
return getByte(HL());
|
2017-07-24 21:00:49 +00:00
|
|
|
case 0b111:
|
|
|
|
return A();
|
|
|
|
default:
|
2017-09-03 20:30:46 +00:00
|
|
|
UNREACHABLE;
|
2017-07-24 21:00:49 +00:00
|
|
|
}
|
|
|
|
throw std::logic_error("Unhandled registry mechanism");
|
|
|
|
}
|
|
|
|
|
2017-08-06 16:06:48 +00:00
|
|
|
void R(int r, uint8_t value) {
|
|
|
|
switch (r) {
|
|
|
|
case 0b000:
|
|
|
|
B() = value;
|
|
|
|
break;
|
|
|
|
case 0b001:
|
|
|
|
C() = value;
|
|
|
|
break;
|
|
|
|
case 0b010:
|
|
|
|
D() = value;
|
|
|
|
break;
|
|
|
|
case 0b011:
|
|
|
|
E() = value;
|
|
|
|
break;
|
|
|
|
case 0b100:
|
|
|
|
H() = value;
|
|
|
|
break;
|
|
|
|
case 0b101:
|
|
|
|
L() = value;
|
|
|
|
break;
|
|
|
|
case 0b110:
|
2017-08-28 17:52:48 +00:00
|
|
|
setByte(HL(), value);
|
2017-08-06 16:06:48 +00:00
|
|
|
break;
|
|
|
|
case 0b111:
|
|
|
|
A() = value;
|
|
|
|
break;
|
|
|
|
default:
|
2017-09-03 20:30:46 +00:00
|
|
|
UNREACHABLE;
|
2017-08-06 16:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 21:00:49 +00:00
|
|
|
register16_t& RP(int rp) {
|
|
|
|
switch (rp) {
|
|
|
|
case 0b00:
|
|
|
|
return BC();
|
|
|
|
case 0b01:
|
|
|
|
return DE();
|
|
|
|
case 0b10:
|
|
|
|
return HL();
|
|
|
|
case 0b11:
|
|
|
|
return SP();
|
|
|
|
default:
|
2017-09-03 20:30:46 +00:00
|
|
|
UNREACHABLE;
|
2017-07-24 21:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
register16_t& RP2(int rp) {
|
|
|
|
switch (rp) {
|
|
|
|
case 0b00:
|
|
|
|
return BC();
|
|
|
|
case 0b01:
|
|
|
|
return DE();
|
|
|
|
case 0b10:
|
|
|
|
return HL();
|
|
|
|
case 0b11:
|
|
|
|
return AF();
|
|
|
|
default:
|
2017-09-03 20:30:46 +00:00
|
|
|
UNREACHABLE;
|
2017-07-24 21:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-06-19 12:53:00 +00:00
|
|
|
static void adjustAuxiliaryCarryAdd(uint8_t& f, uint8_t before, uint8_t value, int calculation) {
|
|
|
|
setFlag(f, AC, calculateHalfCarryAdd(before, value, calculation));
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 12:53:00 +00:00
|
|
|
static void adjustAuxiliaryCarrySub(uint8_t& f, uint8_t before, uint8_t value, int calculation) {
|
|
|
|
clearFlag(f, AC, calculateHalfCarrySub(before, value, calculation));
|
2017-06-04 20:38:34 +00:00
|
|
|
}
|
|
|
|
|
2017-07-24 21:00:49 +00:00
|
|
|
static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-24 21:00:49 +00:00
|
|
|
void execute(int x, int y, int z, int p, int q);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-24 21:00:49 +00:00
|
|
|
static void increment(uint8_t& f, uint8_t& operand);
|
|
|
|
static void decrement(uint8_t& f, uint8_t& operand);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-24 21:00:49 +00:00
|
|
|
bool returnConditionalFlag(uint8_t& f, int flag);
|
|
|
|
bool jumpConditionalFlag(uint8_t& f, int flag);
|
|
|
|
bool callConditionalFlag(uint8_t& f, int flag);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-25 18:26:21 +00:00
|
|
|
static void add(uint8_t& f, register16_t& operand, register16_t value);
|
|
|
|
|
|
|
|
static void add(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0);
|
|
|
|
static void adc(uint8_t& f, uint8_t& operand, uint8_t value);
|
|
|
|
static void sbb(uint8_t& f, uint8_t& operand, uint8_t value);
|
|
|
|
static void andr(uint8_t& f, uint8_t& operand, uint8_t value);
|
|
|
|
static void xorr(uint8_t& f, uint8_t& operand, uint8_t value);
|
|
|
|
static void orr(uint8_t& f, uint8_t& operand, uint8_t value);
|
|
|
|
static void compare(uint8_t& f, uint8_t check, uint8_t value);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-25 20:22:15 +00:00
|
|
|
static void rlc(uint8_t& f, uint8_t& operand);
|
|
|
|
static void rrc(uint8_t& f, uint8_t& operand);
|
|
|
|
static void rl(uint8_t& f, uint8_t& operand);
|
|
|
|
static void rr(uint8_t& f, uint8_t& operand);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-25 20:22:15 +00:00
|
|
|
static void daa(uint8_t& a, uint8_t& f);
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-25 20:22:15 +00:00
|
|
|
static void cma(uint8_t& a, uint8_t& f);
|
|
|
|
static void stc(uint8_t& a, uint8_t& f);
|
|
|
|
static void cmc(uint8_t& a, uint8_t& f);
|
2017-07-24 21:00:49 +00:00
|
|
|
|
|
|
|
void xhtl();
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-22 22:52:58 +00:00
|
|
|
void out();
|
|
|
|
void in();
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-07-22 22:52:58 +00:00
|
|
|
void ei();
|
|
|
|
void di();
|
2017-06-04 20:38:34 +00:00
|
|
|
};
|
|
|
|
}
|