2015-12-01 19:51:45 +00:00
|
|
|
#ifndef __Z80_H__
|
|
|
|
#define __Z80_H__
|
|
|
|
|
|
|
|
#undef sbi
|
|
|
|
#undef inch
|
|
|
|
|
|
|
|
class z80: public CPU {
|
|
|
|
public:
|
2016-01-23 21:15:14 +00:00
|
|
|
z80(Memory &, PortDevice<z80> &);
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
void run(unsigned);
|
|
|
|
void reset();
|
|
|
|
void raise(int level) { _irq_pending = level; }
|
2016-01-24 11:55:50 +00:00
|
|
|
char *status(char *buf, size_t n, bool hdr);
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
void checkpoint(Stream &);
|
|
|
|
void restore(Stream &);
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint8_t a() { return A; }
|
|
|
|
inline uint8_t b() { return B; }
|
|
|
|
inline uint8_t c() { return C; }
|
|
|
|
inline uint8_t d() { return D; }
|
|
|
|
inline uint8_t e() { return E; }
|
|
|
|
inline uint8_t h() { return H; }
|
|
|
|
inline uint8_t l() { return L; }
|
|
|
|
inline uint16_t af() { return AF; }
|
|
|
|
inline uint16_t bc() { return BC; }
|
|
|
|
inline uint16_t de() { return DE; }
|
|
|
|
inline uint16_t hl() { return HL; }
|
|
|
|
inline uint8_t sr() { return F; }
|
|
|
|
inline uint8_t i() { return I; }
|
|
|
|
inline uint8_t r() { return R; }
|
|
|
|
inline uint16_t af_() { return AF_; }
|
|
|
|
inline uint16_t bc_() { return BC_; }
|
|
|
|
inline uint16_t de_() { return DE_; }
|
|
|
|
inline uint16_t hl_() { return HL_; }
|
|
|
|
inline uint16_t ix() { return IX; }
|
|
|
|
inline uint16_t iy() { return IY; }
|
|
|
|
inline uint16_t sp() { return SP; }
|
|
|
|
inline uint16_t pc() { return PC; }
|
2015-12-01 19:51:45 +00:00
|
|
|
inline bool iff1() { return _iff1; }
|
|
|
|
inline bool iff2() { return _iff2; }
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint8_t im() { return _im; }
|
|
|
|
|
|
|
|
inline void af(uint16_t w) { AF = w; }
|
|
|
|
inline void bc(uint16_t w) { BC = w; }
|
|
|
|
inline void de(uint16_t w) { DE = w; }
|
|
|
|
inline void hl(uint16_t w) { HL = w; }
|
|
|
|
inline void pc(uint16_t w) { PC = w; }
|
|
|
|
inline void sp(uint16_t w) { SP = w; }
|
|
|
|
inline void ix(uint16_t w) { IX = w; }
|
|
|
|
inline void iy(uint16_t w) { IY = w; }
|
|
|
|
inline void af_(uint16_t w) { AF_ = w; }
|
|
|
|
inline void bc_(uint16_t w) { BC_ = w; }
|
|
|
|
inline void de_(uint16_t w) { DE_ = w; }
|
|
|
|
inline void hl_(uint16_t w) { HL_ = w; }
|
|
|
|
|
|
|
|
inline void i(uint8_t i) { I = i; }
|
|
|
|
inline void r(uint8_t r) { R = r; }
|
|
|
|
inline void iff1(uint8_t iff1) { _iff1 = iff1 != 0; }
|
|
|
|
inline void iff2(uint8_t iff2) { _iff2 = iff2 != 0; }
|
|
|
|
inline void im(uint8_t im) { _im = im; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
inline unsigned long ts() { return _ts; }
|
|
|
|
inline void ts(int t) { _ts += t; }
|
2015-12-21 12:08:51 +00:00
|
|
|
inline void reset_ts() { _ts = 0; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void _handle_interrupt();
|
|
|
|
|
2018-08-10 10:13:45 +00:00
|
|
|
typedef void (z80::*OP)();
|
2015-12-01 19:51:45 +00:00
|
|
|
void _step(OP ops[]);
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t _fetch_op();
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
inline void step() { (this->*_ops[_fetch_op()])(); }
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
typedef void (z80::*OP_IDX)(uint8_t);
|
2015-12-01 19:51:45 +00:00
|
|
|
void _step_idx(OP_IDX ops[]);
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
void _ddfd(uint16_t &ix, uint8_t &ixL, uint8_t &ixH, OP_IDX ops[]);
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
struct __attribute__((packed)) {
|
|
|
|
unsigned C:1;
|
|
|
|
unsigned N:1;
|
|
|
|
unsigned P:1;
|
|
|
|
unsigned _3:1;
|
|
|
|
unsigned H:1;
|
|
|
|
unsigned _5:1;
|
|
|
|
unsigned Z:1;
|
|
|
|
unsigned S:1;
|
|
|
|
} flags;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t F;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t A;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
2018-08-13 13:41:23 +00:00
|
|
|
uint16_t AF;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
2018-08-13 13:41:23 +00:00
|
|
|
struct { uint8_t C, B; };
|
|
|
|
uint16_t BC;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
|
|
|
union {
|
2018-08-13 13:41:23 +00:00
|
|
|
struct { uint8_t E, D; };
|
|
|
|
uint16_t DE;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
|
|
|
union {
|
2018-08-13 13:41:23 +00:00
|
|
|
struct { uint8_t L, H; };
|
|
|
|
uint16_t HL;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Memory::address SP;
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
uint16_t AF_, BC_, DE_, HL_;
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
union {
|
2018-08-13 13:41:23 +00:00
|
|
|
struct { uint8_t IXL, IXH; };
|
|
|
|
uint16_t IX;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
2018-08-13 13:41:23 +00:00
|
|
|
struct { uint8_t IYL, IYH; };
|
|
|
|
uint16_t IY;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
2018-08-13 13:41:23 +00:00
|
|
|
struct { uint8_t R, I; };
|
|
|
|
uint16_t IR;
|
2015-12-01 19:51:45 +00:00
|
|
|
};
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t _im;
|
2015-12-01 19:51:45 +00:00
|
|
|
bool _iff1, _iff2;
|
|
|
|
|
|
|
|
unsigned long _ts;
|
|
|
|
|
|
|
|
int _irq_pending;
|
|
|
|
PortDevice<z80> *_ports;
|
|
|
|
|
|
|
|
OP _ops[256], _cb[256];
|
|
|
|
OP_IDX _ddcb[256], _fdcb[256];
|
|
|
|
|
|
|
|
static int parity_table[256];
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint8_t _rb(Memory::address a) {
|
2015-12-01 19:51:45 +00:00
|
|
|
#if defined(CPU_DEBUG)
|
2018-08-09 13:23:54 +00:00
|
|
|
printf("%5ld MC %04x\n", _ts, a);
|
2015-12-01 19:51:45 +00:00
|
|
|
#endif
|
|
|
|
ts(3);
|
|
|
|
#if defined(CPU_DEBUG)
|
2018-08-13 13:41:23 +00:00
|
|
|
printf("%5ld MR %04x %02x\n", _ts, a, (uint8_t)_mem[a]);
|
2015-12-01 19:51:45 +00:00
|
|
|
#endif
|
|
|
|
return _mem[a];
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sb(Memory::address a, uint8_t b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
#if defined(CPU_DEBUG)
|
2018-08-09 13:23:54 +00:00
|
|
|
printf("%5ld MC %04x\n", _ts, a);
|
2015-12-01 19:51:45 +00:00
|
|
|
#endif
|
|
|
|
ts(3);
|
|
|
|
#if defined(CPU_DEBUG)
|
2018-08-09 13:23:54 +00:00
|
|
|
printf("%5ld MW %04x %02x\n", _ts, a, b);
|
2015-12-01 19:51:45 +00:00
|
|
|
#endif
|
|
|
|
_mem[a] = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void _mc(Memory::address a, int i) {
|
|
|
|
#if defined(CPU_DEBUG)
|
2018-08-09 13:23:54 +00:00
|
|
|
printf("%5ld MC %04x\n", _ts, a);
|
2015-12-01 19:51:45 +00:00
|
|
|
#endif
|
|
|
|
ts(i);
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint16_t _rw(Memory::address a) {
|
2018-08-10 10:13:45 +00:00
|
|
|
return _rb(a) + (_rb(a+1) << 8);
|
2015-12-01 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sw(Memory::address a, uint16_t w) {
|
2015-12-01 19:51:45 +00:00
|
|
|
_sb(a+1, w >> 8);
|
|
|
|
_sb(a, w & 0xff);
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint16_t _rwpc() {
|
|
|
|
uint16_t w = _rw(PC);
|
2015-12-01 19:51:45 +00:00
|
|
|
PC += 2;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _swPC(uint16_t w) { _sw(_rw(PC), w); PC += 2; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint16_t _rwPC() {
|
|
|
|
uint16_t w = _rw(_rw(PC));
|
2015-12-01 19:51:45 +00:00
|
|
|
PC += 2;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _35(uint8_t r) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags._3 = ((r & 0x08) != 0);
|
|
|
|
flags._5 = ((r & 0x20) != 0);
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sz35(uint8_t r) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.S = ((r & 0x80) != 0);
|
|
|
|
flags.Z = (r == 0);
|
|
|
|
_35(r);
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _szp35(uint8_t r) {
|
2015-12-01 19:51:45 +00:00
|
|
|
_sz35(r);
|
|
|
|
flags.P = parity_table[r];
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _inc(uint8_t &b) {
|
|
|
|
uint16_t w = b + 1;
|
|
|
|
uint8_t r = w & 0xff;
|
2015-12-01 19:51:45 +00:00
|
|
|
_sz35(r);
|
|
|
|
flags.P = r == 0x80;
|
|
|
|
flags.N = 0;
|
|
|
|
flags.H = !(r & 0x0f);
|
|
|
|
b = r;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _dec(uint8_t &b) {
|
|
|
|
uint16_t w = b - 1;
|
|
|
|
uint8_t r = w & 0xff;
|
2015-12-01 19:51:45 +00:00
|
|
|
_sz35(r);
|
|
|
|
flags.P = r == 0x7f;
|
|
|
|
flags.N = 1;
|
|
|
|
flags.H = !(b & 0x0f);
|
|
|
|
b = r;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _add(uint8_t x) {
|
|
|
|
uint16_t w = A + x;
|
|
|
|
uint8_t b = A;
|
2015-12-01 19:51:45 +00:00
|
|
|
A = w & 0xff;
|
|
|
|
_sz35(A);
|
|
|
|
flags.C = w > 0xff;
|
|
|
|
flags.N = 0;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t v = b ^ A ^ x;
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.P = (v >> 7) ^ flags.C;
|
|
|
|
flags.H = (v >> 4) & 1;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _adc(uint8_t x) {
|
|
|
|
uint16_t w = A + x + flags.C;
|
|
|
|
uint8_t b = A;
|
2015-12-01 19:51:45 +00:00
|
|
|
A = w & 0xff;
|
|
|
|
_sz35(A);
|
|
|
|
flags.C = w > 0xff;
|
|
|
|
flags.N = 0;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t v = b ^ A ^ x;
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.P = (v >> 7) ^ flags.C;
|
|
|
|
flags.H = (v >> 4) & 1;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _adc16(uint16_t w) {
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(IR, 1); _mc(IR, 1); _mc(IR, 1);
|
|
|
|
_mc(IR, 1); _mc(IR, 1); _mc(IR, 1); _mc(IR, 1);
|
|
|
|
unsigned long r = HL + w + flags.C;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t h = H;
|
2015-12-01 19:51:45 +00:00
|
|
|
HL = (r & 0xffff);
|
|
|
|
_sz35(H);
|
|
|
|
flags.Z = (HL == 0);
|
|
|
|
flags.C = (r > 0xffff);
|
|
|
|
flags.N = 0;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t v = h ^ H ^ (w >> 8);
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.P = (v >> 7) ^ flags.C;
|
|
|
|
flags.H = (v >> 4) & 1;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _add16(uint16_t ®, uint16_t w) {
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(IR, 1); _mc(IR, 1); _mc(IR, 1);
|
|
|
|
_mc(IR, 1); _mc(IR, 1); _mc(IR, 1); _mc(IR, 1);
|
|
|
|
unsigned long r = reg + w;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t o = reg >> 8;
|
2015-12-01 19:51:45 +00:00
|
|
|
reg = (r & 0xffff);
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t h = reg >> 8;
|
2015-12-01 19:51:45 +00:00
|
|
|
_35(h);
|
|
|
|
flags.C = (r > 0xffff);
|
|
|
|
flags.N = 0;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t v = o ^ h ^ (w >> 8);
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.H = (v >> 4) & 1;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sub(uint8_t x) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = 1;
|
|
|
|
_adc(~x);
|
|
|
|
flags.C = !flags.C;
|
|
|
|
flags.H = !flags.H;
|
|
|
|
flags.N = 1;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sbc(uint8_t x) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = !flags.C;
|
|
|
|
_adc(~x);
|
|
|
|
flags.C = !flags.C;
|
|
|
|
flags.H = !flags.H;
|
|
|
|
flags.N = 1;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sbc16(uint16_t w) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = !flags.C;
|
|
|
|
_adc16(~w);
|
|
|
|
flags.C = !flags.C;
|
|
|
|
flags.H = !flags.H;
|
|
|
|
flags.N = 1;
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint16_t _ads(uint16_t a, uint8_t b) {
|
|
|
|
uint16_t w = a + b;
|
2016-01-21 06:32:44 +00:00
|
|
|
if (b > 127) w -= 0x100;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:51:45 +00:00
|
|
|
inline void _incO(Memory::address a) {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t o = _rb(PC);
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(PC, 1); _mc(PC, 1); _mc(PC, 1);
|
|
|
|
_mc(PC, 1); _mc(PC, 1);
|
|
|
|
PC++;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint16_t w = _ads(a, o);
|
|
|
|
uint8_t b = _rb(w);
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(w, 1);
|
|
|
|
_inc(b);
|
|
|
|
_sb(w, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void _decO(Memory::address a) {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t o = _rb(PC);
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(PC, 1); _mc(PC, 1); _mc(PC, 1);
|
|
|
|
_mc(PC, 1); _mc(PC, 1);
|
|
|
|
PC++;
|
2018-08-13 13:41:23 +00:00
|
|
|
uint16_t w = _ads(a, o);
|
|
|
|
uint8_t b = _rb(w);
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(w, 1);
|
|
|
|
_dec(b);
|
|
|
|
_sb(w, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void _sbO(Memory::address a) {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t o = _rb(PC++);
|
|
|
|
uint8_t b = _rb(PC);
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(PC, 1); _mc(PC, 1);
|
|
|
|
PC++;
|
2016-01-21 06:32:44 +00:00
|
|
|
_sb(_ads(a, o), b);
|
2015-12-01 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint8_t _rbO(Memory::address a) {
|
|
|
|
uint8_t o = _rb(PC);
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(PC, 1); _mc(PC, 1); _mc(PC, 1);
|
|
|
|
_mc(PC, 1); _mc(PC, 1);
|
|
|
|
PC++;
|
2016-01-21 06:32:44 +00:00
|
|
|
return _rb(_ads(a, o));
|
2015-12-01 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sbO(Memory::address a, uint8_t b) {
|
|
|
|
uint8_t o = _rb(PC);
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(PC, 1); _mc(PC, 1); _mc(PC, 1);
|
|
|
|
_mc(PC, 1); _mc(PC, 1);
|
|
|
|
PC++;
|
2016-01-21 06:32:44 +00:00
|
|
|
_sb(_ads(a, o), b);
|
2015-12-01 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _exSP(uint16_t ®) {
|
|
|
|
uint16_t w = _pop();
|
2015-12-01 19:51:45 +00:00
|
|
|
_mc(SP, 1);
|
|
|
|
_push(reg); reg = w;
|
|
|
|
_mc(SP, 1); _mc(SP, 1);
|
|
|
|
}
|
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _exch(uint16_t &a, uint16_t &b) { uint16_t t = b; b = a; a = t; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint16_t _pop() { uint16_t w = _rw(SP); SP += 2; return w; }
|
|
|
|
inline void _push(uint16_t w) { SP -= 2; _sw(SP, w); }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _jmp(uint8_t c) { if (c) jp(); else { _mc(PC, 3); _mc(PC+1, 3); PC += 2; } }
|
|
|
|
inline void _ret(uint8_t c) { _mc(IR, 1); if (c) ret(); }
|
|
|
|
inline void _call(uint8_t c) { if (c) call(); else { _mc(PC, 3); _mc(PC+1, 3); PC += 2; } }
|
|
|
|
inline void _jr(uint8_t c) { if (c) jr(); else { _mc(PC, 3); PC++; } }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0x00
|
|
|
|
void nop() {}
|
|
|
|
void ldbcpc() { BC = _rwpc(); }
|
|
|
|
void ldBCa() { _sb(BC, A); }
|
|
|
|
void incbc() { BC++; _mc(IR, 1); _mc(IR, 1); }
|
|
|
|
void incb() { _inc(B); }
|
|
|
|
void decb() { _dec(B); }
|
|
|
|
void ldb() { B = _rb(PC++); }
|
|
|
|
void rlca() { flags.C = ((A & 0x80) >> 7); A = (A << 1) | flags.C; }
|
|
|
|
|
|
|
|
// 0x08
|
|
|
|
void exaf() { _exch(AF, AF_); }
|
|
|
|
void addhlbc() { _add16(HL, BC); }
|
|
|
|
void ldaBC() { A = _rb(BC); }
|
|
|
|
void decbc() { BC--; _mc(IR, 1); _mc(IR, 1); }
|
|
|
|
void incc() { _inc(C); }
|
|
|
|
void decc() { _dec(C); }
|
|
|
|
void ldc() { C = _rb(PC++); }
|
2018-08-10 10:13:45 +00:00
|
|
|
void rrca() {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.H = flags.N = 0;
|
2018-08-10 10:13:45 +00:00
|
|
|
flags.C = (A & 0x01);
|
|
|
|
A = (A >> 1) | (flags.C << 7);
|
2015-12-01 19:51:45 +00:00
|
|
|
_35(A);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x10
|
|
|
|
void djnz() { _mc(IR, 1); _jr(--B); }
|
|
|
|
void lddepc() { DE = _rwpc(); }
|
|
|
|
void ldDEa() { _sb(DE, A); }
|
|
|
|
void incde() { DE++; _mc(IR, 1); _mc(IR, 1); }
|
|
|
|
void incd() { _inc(D); }
|
|
|
|
void decd() { _dec(D); }
|
|
|
|
void ldd() { D = _rb(PC++); }
|
2018-08-10 10:13:45 +00:00
|
|
|
void rla() {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t b = (A << 1) | flags.C;
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = (A & 0x80) >> 7;
|
|
|
|
A = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x18
|
2018-08-10 10:13:45 +00:00
|
|
|
void jr() {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t b = _rb(PC);
|
2018-08-10 10:13:45 +00:00
|
|
|
_mc(PC, 1); _mc(PC, 1); _mc(PC, 1); _mc(PC, 1); _mc(PC, 1);
|
2016-01-21 06:32:44 +00:00
|
|
|
PC = _ads(PC, b+1);
|
|
|
|
}
|
2015-12-01 19:51:45 +00:00
|
|
|
void addhlde() { _add16(HL, DE); }
|
|
|
|
void ldaDE() { A = _rb(DE); }
|
|
|
|
void decde() { DE--; _mc(IR, 1); _mc(IR, 1); }
|
|
|
|
void ince() { _inc(E); }
|
|
|
|
void dece() { _dec(E); }
|
|
|
|
void lde() { E = _rb(PC++); }
|
|
|
|
void rra() {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint8_t b = (A >> 1) | (flags.C << 7);
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = (A & 1);
|
|
|
|
A = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x20
|
|
|
|
void jrnz() { _jr(!flags.Z); }
|
|
|
|
void ldhlpc() { HL = _rwpc(); }
|
|
|
|
void ldPChl() { _swPC(HL); }
|
|
|
|
void inchl() { HL++; _mc(IR, 1); _mc(IR, 1); }
|
|
|
|
void inch() { _inc(H); }
|
|
|
|
void dech() { _dec(H); }
|
|
|
|
void ldh() { H = _rb(PC++); }
|
|
|
|
void daa();
|
|
|
|
|
|
|
|
// 0x28
|
|
|
|
void jrz() { _jr(flags.Z); }
|
|
|
|
void addhlhl() { _add16(HL, HL); }
|
|
|
|
void ldhlPC() { HL = _rwPC(); }
|
|
|
|
void dechl() { HL--; _mc(IR, 1); _mc(IR, 1); }
|
|
|
|
void incl() { _inc(L); }
|
|
|
|
void decl() { _dec(L); }
|
|
|
|
void ldl() { L = _rb(PC++); }
|
|
|
|
void cpl() { A = ~A; flags.H = flags.N = 1; _35(A); }
|
|
|
|
|
|
|
|
// 0x30
|
|
|
|
void jrnc() { _jr(!flags.C); }
|
|
|
|
void ldsppc() { SP = _rwpc(); }
|
|
|
|
void ldPCa() { _sb(_rw(PC), A); PC += 2; }
|
|
|
|
void incsp() { SP++; _mc(IR, 1); _mc(IR, 1); }
|
2018-08-13 13:41:23 +00:00
|
|
|
void incHL() { uint8_t b = _rb(HL); _mc(HL, 1); _inc(b); _sb(HL, b); }
|
|
|
|
void decHL() { uint8_t b = _rb(HL); _mc(HL, 1); _dec(b); _sb(HL, b); }
|
2015-12-01 19:51:45 +00:00
|
|
|
void ldHL() { _sb(HL, _rb(PC++)); }
|
|
|
|
void scf() { flags.C = 1; flags.N = flags.H = 0; _35(A); }
|
|
|
|
|
|
|
|
// 0x38
|
|
|
|
void jrc() { _jr(flags.C); }
|
|
|
|
void addhlsp() { _add16(HL, SP); }
|
|
|
|
void ldaPC() { A = _rb(_rw(PC)); PC += 2; }
|
|
|
|
void decsp() { SP--; _mc(IR, 1); _mc(IR, 1); }
|
|
|
|
void inca() { _inc(A); }
|
|
|
|
void deca() { _dec(A); }
|
|
|
|
void lda() { A = _rb(PC++); }
|
|
|
|
void ccf() { flags.C = !flags.C; flags.N = 0; _35(A); }
|
|
|
|
|
|
|
|
// 0x40
|
|
|
|
void ldbb() {}
|
|
|
|
void ldbc() { B = C; }
|
|
|
|
void ldbd() { B = D; }
|
|
|
|
void ldbe() { B = E; }
|
|
|
|
void ldbh() { B = H; }
|
|
|
|
void ldbl() { B = L; }
|
|
|
|
void ldbHL() { B = _rb(HL); }
|
|
|
|
void ldba() { B = A; }
|
|
|
|
|
|
|
|
// 0x48
|
|
|
|
void ldcb() { C = B; }
|
|
|
|
void ldcc() {}
|
|
|
|
void ldcd() { C = D; }
|
|
|
|
void ldce() { C = E; }
|
|
|
|
void ldch() { C = H; }
|
|
|
|
void ldcl() { C = L; }
|
|
|
|
void ldcHL() { C = _rb(HL); }
|
|
|
|
void ldca() { C = A; }
|
|
|
|
|
|
|
|
// 0x50
|
|
|
|
void lddb() { D = B; }
|
|
|
|
void lddc() { D = C; }
|
|
|
|
void lddd() {}
|
|
|
|
void ldde() { D = E; }
|
|
|
|
void lddh() { D = H; }
|
|
|
|
void lddl() { D = L; }
|
|
|
|
void lddHL() { D = _rb(HL); }
|
|
|
|
void ldda() { D = A; }
|
|
|
|
|
|
|
|
// 0x58
|
|
|
|
void ldeb() { E = B; }
|
|
|
|
void ldec() { E = C; }
|
|
|
|
void lded() { E = D; }
|
|
|
|
void ldee() {}
|
|
|
|
void ldeh() { E = H; }
|
|
|
|
void ldel() { E = L; }
|
|
|
|
void ldeHL() { E = _rb(HL); }
|
|
|
|
void ldea() { E = A; }
|
|
|
|
|
|
|
|
// 0x60
|
|
|
|
void ldhb() { H = B; }
|
|
|
|
void ldhc() { H = C; }
|
|
|
|
void ldhd() { H = D; }
|
|
|
|
void ldhe() { H = E; }
|
|
|
|
void ldhh() {}
|
|
|
|
void ldhl() { H = L; }
|
|
|
|
void ldhHL() { H = _rb(HL); }
|
|
|
|
void ldha() { H = A; }
|
|
|
|
|
|
|
|
// 0x68
|
|
|
|
void ldlb() { L = B; }
|
|
|
|
void ldlc() { L = C; }
|
|
|
|
void ldld() { L = D; }
|
|
|
|
void ldle() { L = E; }
|
|
|
|
void ldlh() { L = H; }
|
|
|
|
void ldll() {}
|
|
|
|
void ldlHL() { L = _rb(HL); }
|
|
|
|
void ldla() { L = A; }
|
|
|
|
|
|
|
|
// 0x70
|
|
|
|
void ldHLb() { _sb(HL, B); }
|
|
|
|
void ldHLc() { _sb(HL, C); }
|
|
|
|
void ldHLd() { _sb(HL, D); }
|
|
|
|
void ldHLe() { _sb(HL, E); }
|
|
|
|
void ldHLh() { _sb(HL, H); }
|
|
|
|
void ldHLl() { _sb(HL, L); }
|
|
|
|
void halt() { _halted = true; PC--; }
|
|
|
|
void ldHLa() { _sb(HL, A); }
|
|
|
|
|
|
|
|
// 0x78
|
|
|
|
void ldab() { A = B; }
|
|
|
|
void ldac() { A = C; }
|
|
|
|
void ldad() { A = D; }
|
|
|
|
void ldae() { A = E; }
|
|
|
|
void ldah() { A = H; }
|
|
|
|
void ldal() { A = L; }
|
|
|
|
void ldaHL() { A = _rb(HL); }
|
|
|
|
void ldaa() {}
|
|
|
|
|
|
|
|
// 0x80
|
|
|
|
void addab() { _add(B); }
|
|
|
|
void addac() { _add(C); }
|
|
|
|
void addad() { _add(D); }
|
|
|
|
void addae() { _add(E); }
|
|
|
|
void addah() { _add(H); }
|
|
|
|
void addal() { _add(L); }
|
|
|
|
void addaHL() { _add(_rb(HL)); }
|
|
|
|
void addaa() { _add(A); }
|
|
|
|
|
|
|
|
// 0x88
|
|
|
|
void adcab() { _adc(B); }
|
|
|
|
void adcac() { _adc(C); }
|
|
|
|
void adcad() { _adc(D); }
|
|
|
|
void adcae() { _adc(E); }
|
|
|
|
void adcah() { _adc(H); }
|
|
|
|
void adcal() { _adc(L); }
|
|
|
|
void adcaHL() { _adc(_rb(HL)); }
|
|
|
|
void adcaa() { _adc(A); }
|
|
|
|
|
|
|
|
// 0x90
|
|
|
|
void subab() { _sub(B); }
|
|
|
|
void subac() { _sub(C); }
|
|
|
|
void subad() { _sub(D); }
|
|
|
|
void subae() { _sub(E); }
|
|
|
|
void subah() { _sub(H); }
|
|
|
|
void subal() { _sub(L); }
|
|
|
|
void subaHL() { _sub(_rb(HL)); }
|
|
|
|
void subaa() { _sub(A); }
|
|
|
|
|
|
|
|
// 0x98
|
|
|
|
void sbcab() { _sbc(B); }
|
|
|
|
void sbcac() { _sbc(C); }
|
|
|
|
void sbcad() { _sbc(D); }
|
|
|
|
void sbcae() { _sbc(E); }
|
|
|
|
void sbcah() { _sbc(H); }
|
|
|
|
void sbcal() { _sbc(L); }
|
|
|
|
void sbcaHL() { _sbc(_rb(HL)); }
|
|
|
|
void sbcaa() { _sbc(A); }
|
|
|
|
|
|
|
|
// 0xa0
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _and(uint8_t b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
A &= b;
|
|
|
|
_szp35(A);
|
|
|
|
flags.C = flags.N = 0;
|
|
|
|
flags.H = 1;
|
|
|
|
}
|
|
|
|
void andb() { _and(B); }
|
|
|
|
void andc() { _and(C); }
|
|
|
|
void andd() { _and(D); }
|
|
|
|
void ande() { _and(E); }
|
|
|
|
void andh() { _and(H); }
|
|
|
|
void andl() { _and(L); }
|
|
|
|
void andHL() { _and(_rb(HL)); }
|
|
|
|
void anda() { _and(A); }
|
|
|
|
|
|
|
|
// 0xa8
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _xor(uint8_t b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
A ^= b;
|
|
|
|
_szp35(A);
|
|
|
|
flags.C = flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
void xorb() { _xor(B); }
|
|
|
|
void xorc() { _xor(C); }
|
|
|
|
void xord() { _xor(D); }
|
|
|
|
void xore() { _xor(E); }
|
|
|
|
void xorh() { _xor(H); }
|
|
|
|
void xorl() { _xor(L); }
|
|
|
|
void xorHL() { _xor(_rb(HL)); }
|
|
|
|
void xora() { _xor(A); }
|
|
|
|
|
|
|
|
// 0xb0
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _or(uint8_t b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
A |= b;
|
|
|
|
_szp35(A);
|
|
|
|
flags.C = flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
void orb() { _or(B); }
|
|
|
|
void orc() { _or(C); }
|
|
|
|
void ord() { _or(D); }
|
|
|
|
void ore() { _or(E); }
|
|
|
|
void orh() { _or(H); }
|
|
|
|
void orl() { _or(L); }
|
|
|
|
void orHL() { _or(_rb(HL)); }
|
|
|
|
void ora() { _or(A); }
|
|
|
|
|
|
|
|
// 0xb8
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _cmp(uint8_t b) {
|
|
|
|
uint8_t a = A;
|
2015-12-01 19:51:45 +00:00
|
|
|
_sub(b);
|
|
|
|
_35(b);
|
|
|
|
A = a;
|
|
|
|
}
|
|
|
|
void cpb() { _cmp(B); }
|
|
|
|
void cpc() { _cmp(C); }
|
|
|
|
void cpd() { _cmp(D); }
|
|
|
|
void cpe() { _cmp(E); }
|
|
|
|
void cph() { _cmp(H); }
|
|
|
|
void cpL() { _cmp(L); }
|
|
|
|
void cpHL() { _cmp(_rb(HL)); }
|
|
|
|
void cpa() { _cmp(A); }
|
|
|
|
|
|
|
|
// 0xc0
|
|
|
|
void retnz() { _ret(!flags.Z); }
|
|
|
|
void popbc() { BC = _pop(); }
|
|
|
|
void jpnz() { _jmp(!flags.Z); }
|
|
|
|
void jp() { PC = _rw(PC); }
|
|
|
|
void callnz() { _call(!flags.Z); }
|
|
|
|
void pushbc() { _mc(IR, 1); _push(BC); }
|
|
|
|
void adda() { _add(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst00() { _mc(IR, 11); _push(PC); PC = 0x00; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xc8
|
|
|
|
void retz() { _ret(flags.Z); }
|
|
|
|
void ret() { PC = _pop(); }
|
|
|
|
void jpz() { _jmp(flags.Z); }
|
|
|
|
void cb() { (this->*_cb[_fetch_op()])(); }
|
|
|
|
void callz() { _call(flags.Z); }
|
2018-08-13 13:41:23 +00:00
|
|
|
void call() { uint16_t pc = _rw(PC); _mc(PC+1, 1); _push(PC+2); PC = pc; }
|
2015-12-01 19:51:45 +00:00
|
|
|
void adca() { _adc(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst08() { _mc(IR, 11); _push(PC); PC = 0x08; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xd0
|
|
|
|
void retnc() { _ret(!flags.C); }
|
|
|
|
void popde() { DE = _pop(); }
|
|
|
|
void jpnc() { _jmp(!flags.C); }
|
|
|
|
void outa() {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint16_t p = _rb(PC++) + (A << 8);
|
2015-12-01 19:51:45 +00:00
|
|
|
_ports->out(p, A, this);
|
|
|
|
}
|
|
|
|
void callnc() { _call(!flags.C); }
|
|
|
|
void pushde() { _mc(IR, 1); _push(DE); }
|
|
|
|
void suba() { _sub(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst10() { _mc(IR, 11); _push(PC); PC = 0x10; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xd8
|
|
|
|
void retc() { _ret(flags.C); }
|
|
|
|
void exx() { _exch(BC, BC_); _exch(DE, DE_); _exch(HL, HL_); }
|
|
|
|
void jpc() { _jmp(flags.C); }
|
|
|
|
void ina() {
|
2018-08-13 13:41:23 +00:00
|
|
|
uint16_t p = _rb(PC++) + (A << 8);
|
2015-12-01 19:51:45 +00:00
|
|
|
A = _ports->in(p, this);
|
|
|
|
}
|
|
|
|
void callc() { _call(flags.C); }
|
|
|
|
void dd() { _ddfd(IX, IXL, IXH, _ddcb); }
|
|
|
|
void sbca() { _sbc(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst18() { _mc(IR, 11); _push(PC); PC = 0x18; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xe0
|
|
|
|
void retpo() { _ret(!flags.P); }
|
|
|
|
void pophl() { HL = _pop(); }
|
|
|
|
void jppo() { _jmp(!flags.P); }
|
|
|
|
void exSPhl() { _exSP(HL); }
|
|
|
|
void callpo() { _call(!flags.P); }
|
|
|
|
void pushhl() { _mc(IR, 1); _push(HL); }
|
2017-10-05 08:55:39 +00:00
|
|
|
void and_() { _and(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst20() { _mc(IR, 11); _push(PC); PC = 0x20; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xe8
|
2018-08-13 13:41:23 +00:00
|
|
|
inline uint8_t _inr(uint16_t p) {
|
|
|
|
uint8_t b = _ports->in(p, this);
|
2015-12-01 19:51:45 +00:00
|
|
|
_szp35(b);
|
|
|
|
flags.N = flags.H = 0;
|
|
|
|
return b;
|
|
|
|
}
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _outr(uint16_t p, uint8_t b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
_ports->out(p, b, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void retpe() { _ret(flags.P); }
|
|
|
|
void jphl() { PC = HL; }
|
|
|
|
void jppe() { _jmp(flags.P); }
|
|
|
|
void exdehl() { _exch(DE, HL); }
|
|
|
|
void callpe() { _call(flags.P); }
|
|
|
|
void ed();
|
2017-10-05 08:55:39 +00:00
|
|
|
void xor_() { _xor(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst28() { _mc(IR, 11); _push(PC); PC = 0x28; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xf0
|
|
|
|
void retp() { _ret(!flags.S); }
|
|
|
|
void popaf() { AF = _pop(); }
|
|
|
|
void jpp() { _jmp(!flags.S); }
|
|
|
|
void di() { _iff1 = _iff2 = false; }
|
|
|
|
void callp() { _call(!flags.S); }
|
|
|
|
void pushaf() { _mc(IR, 1); _push(AF); }
|
2017-10-05 08:55:39 +00:00
|
|
|
void or_() { _or(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst30() { _mc(IR, 11); _push(PC); PC = 0x30; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xf8
|
|
|
|
void retm() { _ret(flags.S); }
|
|
|
|
void ldsphl() { _mc(IR, 1); _mc(IR, 1); SP = HL; }
|
|
|
|
void jpm() { _jmp(flags.S); }
|
|
|
|
void ei() { _iff1 = _iff2 = true; }
|
|
|
|
void callm() { _call(flags.S); }
|
|
|
|
void fd() { _ddfd(IY, IYL, IYH, _fdcb); }
|
|
|
|
void cp() { _cmp(_rb(PC++)); }
|
2016-01-29 22:24:16 +00:00
|
|
|
void rst38() { _mc(IR, 11); _push(PC); PC = 0x38; }
|
2015-12-01 19:51:45 +00:00
|
|
|
|
|
|
|
// 0xCB extended instructions
|
|
|
|
|
|
|
|
// 0x00
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _rlc(uint8_t &b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
b = (b << 1) | (b >> 7);
|
|
|
|
flags.C = b & 0x01;
|
|
|
|
_szp35(b);
|
|
|
|
flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rlcB() { _rlc(B); }
|
|
|
|
void rlcC() { _rlc(C); }
|
|
|
|
void rlcD() { _rlc(D); }
|
|
|
|
void rlcE() { _rlc(E); }
|
|
|
|
void rlcH() { _rlc(H); }
|
|
|
|
void rlcL() { _rlc(L); }
|
2018-08-13 13:41:23 +00:00
|
|
|
void rlcHL() { uint8_t b = _rb(HL); _mc(HL, 1); _rlc(b); _sb(HL, b); }
|
2015-12-01 19:51:45 +00:00
|
|
|
void rlcA() { _rlc(A); }
|
|
|
|
|
|
|
|
// 0x08
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _rrc(uint8_t &b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = b & 0x01;
|
|
|
|
b = (b >> 1) | (b << 7);
|
|
|
|
_szp35(b);
|
|
|
|
flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rrcB() { _rrc(B); }
|
|
|
|
void rrcC() { _rrc(C); }
|
|
|
|
void rrcD() { _rrc(D); }
|
|
|
|
void rrcE() { _rrc(E); }
|
|
|
|
void rrcH() { _rrc(H); }
|
|
|
|
void rrcL() { _rrc(L); }
|
2018-08-13 13:41:23 +00:00
|
|
|
void rrcHL() { uint8_t b = _rb(HL); _mc(HL, 1); _rrc(b); _sb(HL, b); }
|
2015-12-01 19:51:45 +00:00
|
|
|
void rrcA() { _rrc(A); }
|
|
|
|
|
|
|
|
// 0x10
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _rl(uint8_t &b) {
|
|
|
|
uint8_t a = b;
|
2015-12-01 19:51:45 +00:00
|
|
|
b = (b << 1) | flags.C;
|
|
|
|
flags.C = (a >> 7);
|
|
|
|
_szp35(b);
|
|
|
|
flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rlB() { _rl(B); }
|
|
|
|
void rlC() { _rl(C); }
|
|
|
|
void rlD() { _rl(D); }
|
|
|
|
void rlE() { _rl(E); }
|
|
|
|
void rlH() { _rl(H); }
|
|
|
|
void rlL() { _rl(L); }
|
2018-08-13 13:41:23 +00:00
|
|
|
void rlHL() { uint8_t b = _rb(HL); _mc(HL, 1); _rl(b); _sb(HL, b); }
|
2015-12-01 19:51:45 +00:00
|
|
|
void rlA() { _rl(A); }
|
|
|
|
|
|
|
|
// 0x18
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _rr(uint8_t &b) {
|
|
|
|
uint8_t a = b;
|
2015-12-01 19:51:45 +00:00
|
|
|
b >>= 1;
|
|
|
|
if (flags.C) b |= 0x80;
|
|
|
|
flags.C = a & 0x01;
|
|
|
|
_szp35(b);
|
|
|
|
flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rrB() { _rr(B); }
|
|
|
|
void rrC() { _rr(C); }
|
|
|
|
void rrD() { _rr(D); }
|
|
|
|
void rrE() { _rr(E); }
|
|
|
|
void rrH() { _rr(H); }
|
|
|
|
void rrL() { _rr(L); }
|
2018-08-13 13:41:23 +00:00
|
|
|
void rrHL() { uint8_t b = _rb(HL); _mc(HL, 1); _rr(b); _sb(HL, b); }
|
2015-12-01 19:51:45 +00:00
|
|
|
void rrA() { _rr(A); }
|
|
|
|
|
|
|
|
// 0x20
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sla(uint8_t &b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = (b & 0x80) != 0;
|
|
|
|
b <<= 1;
|
|
|
|
_szp35(b);
|
|
|
|
flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void slab() { _sla(B); }
|
|
|
|
void slac() { _sla(C); }
|
|
|
|
void slad() { _sla(D); }
|
|
|
|
void slae() { _sla(E); }
|
|
|
|
void slah() { _sla(H); }
|
|
|
|
void slal() { _sla(L); }
|
2018-08-13 13:41:23 +00:00
|
|
|
void slaHL() { uint8_t b = _rb(HL); _mc(HL, 1); _sla(b); _sb(HL, b); }
|
2015-12-01 19:51:45 +00:00
|
|
|
void slaa() { _sla(A); }
|
|
|
|
|
|
|
|
// 0x28
|
2018-08-13 13:41:23 +00:00
|
|
|
inline void _sra(uint8_t &b) {
|
2015-12-01 19:51:45 +00:00
|
|
|
flags.C = b & 0x01;
|
|
|
|
b = (b & 0x80) | (b >> 1);
|
|
|
|
_szp35(b);
|
|
|
|
flags.N = flags.H = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void srab() { _sra(B); }
|
|
|
|
void srac() { _sra(C); } |