1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-06-18 14:29:32 +00:00

replace opcode table with switch

This commit is contained in:
Stephen Crane 2019-02-24 11:30:53 +00:00
parent ab85adce3d
commit 76eb94202c
2 changed files with 382 additions and 384 deletions

274
i8080.cpp
View File

@ -10,7 +10,7 @@ void i8080::run(unsigned clocks) {
while (clocks--) {
uint8_t op = _mem[PC];
PC++;
(this->*_ops[op])();
_op(op);
if (_halted)
break;
}
@ -34,12 +34,6 @@ void i8080::raise(int level) {
_irq_pending = level;
}
void i8080::ei() {
flags.I = 1;
if (_irq_pending)
raise(_irq_pending);
}
char *i8080::status(char *buf, size_t n, bool hdr) {
#if defined(CPU_DEBUG)
uint8_t op = _mem[PC];
@ -105,169 +99,173 @@ int i8080::parity_table[] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
};
i8080::i8080(Memory &m, PortDevice<i8080> &d): CPU(m)
i8080::i8080(Memory &m, PortDevice<i8080> &d): CPU(m), _ports(&d)
{
_ports = &d;
}
OP *p = _ops;
void i8080::_op(uint8_t op) {
#define O(o, e) case o: e; break;
switch(op) {
// 0x
*p++ = &i8080::nop; *p++ = &i8080::lxib;
*p++ = &i8080::staxb; *p++ = &i8080::inxb;
*p++ = &i8080::inrb; *p++ = &i8080::dcrb;
*p++ = &i8080::mvib; *p++ = &i8080::rlc;
*p++ = &i8080::nop; *p++ = &i8080::dadb;
*p++ = &i8080::ldaxb; *p++ = &i8080::dcxb;
*p++ = &i8080::inrc; *p++ = &i8080::dcrc;
*p++ = &i8080::mvic; *p++ = &i8080::rrc;
O(0x00, nop()); O(0x01, lxib());
O(0x02, staxb()); O(0x03, inxb());
O(0x04, inrb()); O(0x05, dcrb());
O(0x06, mvib()); O(0x07, rlc());
O(0x08, nop()); O(0x09, dadb());
O(0x0a, ldaxb()); O(0x0b, dcxb());
O(0x0c, inrc()); O(0x0d, dcrc());
O(0x0e, mvic()); O(0x0f, rrc());
// 1x
*p++ = &i8080::nop; *p++ = &i8080::lxid;
*p++ = &i8080::staxd; *p++ = &i8080::inxd;
*p++ = &i8080::inrd; *p++ = &i8080::dcrd;
*p++ = &i8080::mvid; *p++ = &i8080::ral;
*p++ = &i8080::nop; *p++ = &i8080::dadd;
*p++ = &i8080::ldaxd; *p++ = &i8080::dcxd;
*p++ = &i8080::inre; *p++ = &i8080::dcre;
*p++ = &i8080::mvie; *p++ = &i8080::rar;
O(0x10, nop()); O(0x11, lxid());
O(0x12, staxd()); O(0x13, inxd());
O(0x14, inrd()); O(0x15, dcrd());
O(0x16, mvid()); O(0x17, ral());
O(0x18, nop()); O(0x19, dadd());
O(0x1a, ldaxd()); O(0x1b, dcxd());
O(0x1c, inre()); O(0x1d, dcre());
O(0x1e, mvie()); O(0x1f, rar());
// 2x
*p++ = &i8080::nop; *p++ = &i8080::lxih;
*p++ = &i8080::shld; *p++ = &i8080::inxh;
*p++ = &i8080::inrh; *p++ = &i8080::dcrh;
*p++ = &i8080::mvih; *p++ = &i8080::daa;
*p++ = &i8080::nop; *p++ = &i8080::dadh;
*p++ = &i8080::lhld; *p++ = &i8080::dcxh;
*p++ = &i8080::inrl; *p++ = &i8080::dcrl;
*p++ = &i8080::mvil; *p++ = &i8080::cma;
O(0x20, nop()); O(0x21, lxih());
O(0x22, shld()); O(0x23, inxh());
O(0x24, inrh()); O(0x25, dcrh());
O(0x26, mvih()); O(0x27, daa());
O(0x28, nop()); O(0x29, dadh());
O(0x2a, lhld()); O(0x2b, dcxh());
O(0x2c, inrl()); O(0x2d, dcrl());
O(0x2e, mvil()); O(0x2f, cma());
// 3x
*p++ = &i8080::nop; *p++ = &i8080::lxisp;
*p++ = &i8080::sta; *p++ = &i8080::inxsp;
*p++ = &i8080::inrm; *p++ = &i8080::dcrm;
*p++ = &i8080::mvim; *p++ = &i8080::stc;
*p++ = &i8080::nop; *p++ = &i8080::dadsp;
*p++ = &i8080::lda; *p++ = &i8080::dcxsp;
*p++ = &i8080::inra; *p++ = &i8080::dcra;
*p++ = &i8080::mvia; *p++ = &i8080::cmc;
O(0x30, nop()); O(0x31, lxisp());
O(0x32, sta()); O(0x33, inxsp());
O(0x34, inrm()); O(0x35, dcrm());
O(0x36, mvim()); O(0x37, stc());
O(0x38, nop()); O(0x39, dadsp());
O(0x3a, lda()); O(0x3b, dcxsp());
O(0x3c, inra()); O(0x3d, dcra());
O(0x3e, mvia()); O(0x3f, cmc());
// 4x
*p++ = &i8080::movbb; *p++ = &i8080::movbc;
*p++ = &i8080::movbd; *p++ = &i8080::movbe;
*p++ = &i8080::movbh; *p++ = &i8080::movbl;
*p++ = &i8080::movbm; *p++ = &i8080::movba;
*p++ = &i8080::movcb; *p++ = &i8080::movcc;
*p++ = &i8080::movcd; *p++ = &i8080::movce;
*p++ = &i8080::movch; *p++ = &i8080::movcl;
*p++ = &i8080::movcm; *p++ = &i8080::movca;
O(0x40, movbb()); O(0x41, movbc());
O(0x42, movbd()); O(0x43, movbe());
O(0x44, movbh()); O(0x45, movbl());
O(0x46, movbm()); O(0x47, movba());
O(0x48, movcb()); O(0x49, movcc());
O(0x4a, movcd()); O(0x4b, movce());
O(0x4c, movch()); O(0x4d, movcl());
O(0x4e, movcm()); O(0x4f, movca());
// 5x
*p++ = &i8080::movdb; *p++ = &i8080::movdc;
*p++ = &i8080::movdd; *p++ = &i8080::movde;
*p++ = &i8080::movdh; *p++ = &i8080::movdl;
*p++ = &i8080::movdm; *p++ = &i8080::movda;
*p++ = &i8080::moveb; *p++ = &i8080::movec;
*p++ = &i8080::moved; *p++ = &i8080::movee;
*p++ = &i8080::moveh; *p++ = &i8080::movel;
*p++ = &i8080::movem; *p++ = &i8080::movea;
O(0x50, movdb()); O(0x51, movdc());
O(0x52, movdd()); O(0x53, movde());
O(0x54, movdh()); O(0x55, movdl());
O(0x56, movdm()); O(0x57, movda());
O(0x58, moveb()); O(0x59, movec());
O(0x5a, moved()); O(0x5b, movee());
O(0x5c, moveh()); O(0x5d, movel());
O(0x5e, movem()); O(0x5f, movea());
// 6x
*p++ = &i8080::movhb; *p++ = &i8080::movhc;
*p++ = &i8080::movhd; *p++ = &i8080::movhe;
*p++ = &i8080::movhh; *p++ = &i8080::movhl;
*p++ = &i8080::movhm; *p++ = &i8080::movha;
*p++ = &i8080::movlb; *p++ = &i8080::movlc;
*p++ = &i8080::movld; *p++ = &i8080::movle;
*p++ = &i8080::movlh; *p++ = &i8080::movll;
*p++ = &i8080::movlm; *p++ = &i8080::movla;
O(0x60, movhb()); O(0x61, movhc());
O(0x62, movhd()); O(0x63, movhe());
O(0x64, movhh()); O(0x65, movhl());
O(0x66, movhm()); O(0x67, movha());
O(0x68, movlb()); O(0x69, movlc());
O(0x6a, movld()); O(0x6b, movle());
O(0x6c, movlh()); O(0x6d, movll());
O(0x6e, movlm()); O(0x6f, movla());
// 7x
*p++ = &i8080::movmb; *p++ = &i8080::movmc;
*p++ = &i8080::movmd; *p++ = &i8080::movme;
*p++ = &i8080::movmh; *p++ = &i8080::movml;
*p++ = &i8080::hlt; *p++ = &i8080::movma;
*p++ = &i8080::movab; *p++ = &i8080::movac;
*p++ = &i8080::movad; *p++ = &i8080::movae;
*p++ = &i8080::movah; *p++ = &i8080::moval;
*p++ = &i8080::movam; *p++ = &i8080::movaa;
O(0x70, movmb()); O(0x71, movmc());
O(0x72, movmd()); O(0x73, movme());
O(0x74, movmh()); O(0x75, movml());
O(0x76, hlt()); O(0x77, movma());
O(0x78, movab()); O(0x79, movac());
O(0x7a, movad()); O(0x7b, movae());
O(0x7c, movah()); O(0x7d, moval());
O(0x7e, movam()); O(0x7f, movaa());
// 8x
*p++ = &i8080::addb; *p++ = &i8080::addc;
*p++ = &i8080::addd; *p++ = &i8080::adde;
*p++ = &i8080::addh; *p++ = &i8080::addl;
*p++ = &i8080::addm; *p++ = &i8080::adda;
*p++ = &i8080::adcb; *p++ = &i8080::adcc;
*p++ = &i8080::adcd; *p++ = &i8080::adce;
*p++ = &i8080::adch; *p++ = &i8080::adcl;
*p++ = &i8080::adcm; *p++ = &i8080::adca;
O(0x80, addb()); O(0x81, addc());
O(0x82, addd()); O(0x83, adde());
O(0x84, addh()); O(0x85, addl());
O(0x86, addm()); O(0x87, adda());
O(0x88, adcb()); O(0x89, adcc());
O(0x8a, adcd()); O(0x8b, adce());
O(0x8c, adch()); O(0x8d, adcl());
O(0x8e, adcm()); O(0x8f, adca());
// 9x
*p++ = &i8080::subb; *p++ = &i8080::subc;
*p++ = &i8080::subd; *p++ = &i8080::sube;
*p++ = &i8080::subh; *p++ = &i8080::subl;
*p++ = &i8080::subm; *p++ = &i8080::suba;
*p++ = &i8080::sbbb; *p++ = &i8080::sbbc;
*p++ = &i8080::sbbd; *p++ = &i8080::sbbe;
*p++ = &i8080::sbbh; *p++ = &i8080::sbbl;
*p++ = &i8080::sbbm; *p++ = &i8080::sbba;
O(0x90, subb()); O(0x91, subc());
O(0x92, subd()); O(0x93, sube());
O(0x94, subh()); O(0x95, subl());
O(0x96, subm()); O(0x97, suba());
O(0x98, sbbb()); O(0x99, sbbc());
O(0x9a, sbbd()); O(0x9b, sbbe());
O(0x9c, sbbh()); O(0x9d, sbbl());
O(0x9e, sbbm()); O(0x9f, sbba());
// Ax
*p++ = &i8080::anab; *p++ = &i8080::anac;
*p++ = &i8080::anad; *p++ = &i8080::anae;
*p++ = &i8080::anah; *p++ = &i8080::anal;
*p++ = &i8080::anam; *p++ = &i8080::anaa;
*p++ = &i8080::xrab; *p++ = &i8080::xrac;
*p++ = &i8080::xrad; *p++ = &i8080::xrae;
*p++ = &i8080::xrah; *p++ = &i8080::xral;
*p++ = &i8080::xram; *p++ = &i8080::xraa;
O(0xa0, anab()); O(0xa1, anac());
O(0xa2, anad()); O(0xa3, anae());
O(0xa4, anah()); O(0xa5, anal());
O(0xa6, anam()); O(0xa7, anaa());
O(0xa8, xrab()); O(0xa9, xrac());
O(0xaa, xrad()); O(0xab, xrae());
O(0xac, xrah()); O(0xad, xral());
O(0xae, xram()); O(0xaf, xraa());
// Bx
*p++ = &i8080::orab; *p++ = &i8080::orac;
*p++ = &i8080::orad; *p++ = &i8080::orae;
*p++ = &i8080::orah; *p++ = &i8080::oral;
*p++ = &i8080::oram; *p++ = &i8080::oraa;
*p++ = &i8080::cmpb; *p++ = &i8080::cmpc;
*p++ = &i8080::cmpd; *p++ = &i8080::cmpe;
*p++ = &i8080::cmph; *p++ = &i8080::cmpl;
*p++ = &i8080::cmpm; *p++ = &i8080::cmpa;
O(0xb0, orab()); O(0xb1, orac());
O(0xb2, orad()); O(0xb3, orae());
O(0xb4, orah()); O(0xb5, oral());
O(0xb6, oram()); O(0xb7, oraa());
O(0xb8, cmpb()); O(0xb9, cmpc());
O(0xba, cmpd()); O(0xbb, cmpe());
O(0xbc, cmph()); O(0xbd, cmpl());
O(0xbe, cmpm()); O(0xbf, cmpa());
// Cx
*p++ = &i8080::rnz; *p++ = &i8080::popb;
*p++ = &i8080::jnz; *p++ = &i8080::jmp;
*p++ = &i8080::cnz; *p++ = &i8080::pushb;
*p++ = &i8080::adi; *p++ = &i8080::rst0;
*p++ = &i8080::rz; *p++ = &i8080::ret;
*p++ = &i8080::jz; *p++ = &i8080::jmp;
*p++ = &i8080::cz; *p++ = &i8080::call;
*p++ = &i8080::aci; *p++ = &i8080::rst1;
O(0xc0, rnz()); O(0xc1, popb());
O(0xc2, jnz()); O(0xc3, jmp());
O(0xc4, cnz()); O(0xc5, pushb());
O(0xc6, adi()); O(0xc7, rst0());
O(0xc8, rz()); O(0xc9, ret());
O(0xca, jz()); O(0xcb, jmp());
O(0xcc, cz()); O(0xcd, call());
O(0xce, aci()); O(0xcf, rst1());
// Dx
*p++ = &i8080::rnc; *p++ = &i8080::popd;
*p++ = &i8080::jnc; *p++ = &i8080::out;
*p++ = &i8080::cnc; *p++ = &i8080::pushd;
*p++ = &i8080::sui; *p++ = &i8080::rst2;
*p++ = &i8080::rc; *p++ = &i8080::ret;
*p++ = &i8080::jc; *p++ = &i8080::in;
*p++ = &i8080::cc; *p++ = &i8080::call;
*p++ = &i8080::sbi; *p++ = &i8080::rst3;
O(0xd0, rnc()); O(0xd1, popd());
O(0xd2, jnc()); O(0xd3, out());
O(0xd4, cnc()); O(0xd5, pushd());
O(0xd6, sui()); O(0xd7, rst2());
O(0xd8, rc()); O(0xd9, ret());
O(0xda, jc()); O(0xdb, in());
O(0xdc, cc()); O(0xdd, call());
O(0xde, sbi()); O(0xdf, rst3());
// Ex
*p++ = &i8080::rpo; *p++ = &i8080::poph;
*p++ = &i8080::jpo; *p++ = &i8080::xthl;
*p++ = &i8080::cpo; *p++ = &i8080::pushh;
*p++ = &i8080::ani; *p++ = &i8080::rst4;
*p++ = &i8080::rpe; *p++ = &i8080::pchl;
*p++ = &i8080::jpe; *p++ = &i8080::xchg;
*p++ = &i8080::cpe; *p++ = &i8080::call;
*p++ = &i8080::xri; *p++ = &i8080::rst5;
O(0xe0, rpo()); O(0xe1, poph());
O(0xe2, jpo()); O(0xe3, xthl());
O(0xe4, cpo()); O(0xe5, pushh());
O(0xe6, ani()); O(0xe7, rst4());
O(0xe8, rpe()); O(0xe9, pchl());
O(0xea, jpe()); O(0xeb, xchg());
O(0xec, cpe()); O(0xed, call());
O(0xee, xri()); O(0xef, rst5());
// Fx
*p++ = &i8080::rp; *p++ = &i8080::pop;
*p++ = &i8080::jp; *p++ = &i8080::di;
*p++ = &i8080::cp; *p++ = &i8080::push;
*p++ = &i8080::ori; *p++ = &i8080::rst6;
*p++ = &i8080::rm; *p++ = &i8080::sphl;
*p++ = &i8080::jm; *p++ = &i8080::ei;
*p++ = &i8080::cm; *p++ = &i8080::call;
*p++ = &i8080::cpi; *p++ = &i8080::rst7;
O(0xf0, rp()); O(0xf1, pop());
O(0xf2, jp()); O(0xf3, di());
O(0xf4, cp()); O(0xf5, push());
O(0xf6, ori()); O(0xf7, rst6());
O(0xf8, rm()); O(0xf9, sphl());
O(0xfa, jm()); O(0xfb, ei());
O(0xfc, cm()); O(0xfd, call());
O(0xfe, cpi()); O(0xff, rst7());
}
}

492
i8080.h
View File

@ -60,14 +60,14 @@ private:
int _irq_pending;
PortDevice<i8080> *_ports;
typedef void (i8080::*OP)();
OP _ops[256];
void _op(uint8_t op);
static int parity_table[256];
inline uint16_t _rw(Memory::address a) {
return _mem[a] + (_mem[a+1] << 8);
}
inline void _sw(Memory::address a, uint16_t w) {
_mem[a] = (w & 0xff);
_mem[a+1] = (w >> 8);
@ -106,142 +106,142 @@ private:
flags.C = (r > 0xffff);
}
void nop() {}
void lxib() { BC = _rw(PC); PC += 2; }
void staxb() { _mem[BC] = A; }
void inxb() { BC++; }
void inrb() { _inc(B); }
void dcrb() { _dec(B); }
void mvib() { B = _mem[PC++]; }
void rlc() { flags.C = ((A & 0x80) >> 7); A = (A << 1) | flags.C; }
inline void nop() {}
inline void lxib() { BC = _rw(PC); PC += 2; }
inline void staxb() { _mem[BC] = A; }
inline void inxb() { BC++; }
inline void inrb() { _inc(B); }
inline void dcrb() { _dec(B); }
inline void mvib() { B = _mem[PC++]; }
inline void rlc() { flags.C = ((A & 0x80) >> 7); A = (A << 1) | flags.C; }
void dadb() { _dad(BC); }
void ldaxb() { A = _mem[BC]; }
void dcxb() { BC--; }
void inrc() { _inc(C); }
void dcrc() { _dec(C); }
void mvic() { C = _mem[PC++]; }
void rrc() { flags.C = (A & 0x01); A = (A >> 1) | (flags.C << 7); }
inline void dadb() { _dad(BC); }
inline void ldaxb() { A = _mem[BC]; }
inline void dcxb() { BC--; }
inline void inrc() { _inc(C); }
inline void dcrc() { _dec(C); }
inline void mvic() { C = _mem[PC++]; }
inline void rrc() { flags.C = (A & 0x01); A = (A >> 1) | (flags.C << 7); }
void lxid() { DE = _rw(PC); PC += 2; }
void staxd() { _mem[DE] = A; }
void inxd() { DE++; }
void inrd() { _inc(D); }
void dcrd() { _dec(D); }
void mvid() { D = _mem[PC++]; }
void ral() {
inline void lxid() { DE = _rw(PC); PC += 2; }
inline void staxd() { _mem[DE] = A; }
inline void inxd() { DE++; }
inline void inrd() { _inc(D); }
inline void dcrd() { _dec(D); }
inline void mvid() { D = _mem[PC++]; }
inline void ral() {
uint8_t b = (A << 1) | flags.C;
flags.C = (A & 0x80) >> 7;
A = b;
}
void dadd() { _dad(DE); }
void ldaxd() { A = _mem[DE]; }
void dcxd() { DE--; }
void inre() { _inc(E); }
void dcre() { _dec(E); }
void mvie() { E = _mem[PC++]; }
void rar() {
inline void dadd() { _dad(DE); }
inline void ldaxd() { A = _mem[DE]; }
inline void dcxd() { DE--; }
inline void inre() { _inc(E); }
inline void dcre() { _dec(E); }
inline void mvie() { E = _mem[PC++]; }
inline void rar() {
uint8_t b = (A >> 1) | (flags.C << 7);
flags.C = (A & 1);
A = b;
}
void lxih() { HL = _rw(PC); PC += 2; }
void shld() { _sw(_rw(PC), HL); PC += 2; }
void inxh() { HL++; }
void inrh() { _inc(H); }
void dcrh() { _dec(H); }
void mvih() { H = _mem[PC++]; }
void daa();
void dadh() { _dad(HL); }
void lhld() { HL = _rw(_rw(PC)); PC += 2; }
void dcxh() { HL--; }
void inrl() { _inc(L); }
void dcrl() { _dec(L); }
void mvil() { L = _mem[PC++]; }
void cma() { A = ~A; }
inline void lxih() { HL = _rw(PC); PC += 2; }
inline void shld() { _sw(_rw(PC), HL); PC += 2; }
inline void inxh() { HL++; }
inline void inrh() { _inc(H); }
inline void dcrh() { _dec(H); }
inline void mvih() { H = _mem[PC++]; }
inline void daa();
inline void dadh() { _dad(HL); }
inline void lhld() { HL = _rw(_rw(PC)); PC += 2; }
inline void dcxh() { HL--; }
inline void inrl() { _inc(L); }
inline void dcrl() { _dec(L); }
inline void mvil() { L = _mem[PC++]; }
inline void cma() { A = ~A; }
void lxisp() { SP = _rw(PC); PC += 2; }
void sta() { _mem[_rw(PC)] = A; PC += 2; }
void inxsp() { SP++; }
void inrm() { uint8_t b = _mem[HL]; _inc(b); _mem[HL] = b; }
void dcrm() { uint8_t b = _mem[HL]; _dec(b); _mem[HL] = b; }
void mvim() { uint8_t b = _mem[PC++]; _mem[HL] = b; }
void stc() { flags.C = 1; }
inline void lxisp() { SP = _rw(PC); PC += 2; }
inline void sta() { _mem[_rw(PC)] = A; PC += 2; }
inline void inxsp() { SP++; }
inline void inrm() { uint8_t b = _mem[HL]; _inc(b); _mem[HL] = b; }
inline void dcrm() { uint8_t b = _mem[HL]; _dec(b); _mem[HL] = b; }
inline void mvim() { uint8_t b = _mem[PC++]; _mem[HL] = b; }
inline void stc() { flags.C = 1; }
void dadsp() { _dad(SP); }
void lda() { A = _mem[_rw(PC)]; PC += 2; }
void dcxsp() { SP--; }
void inra() { _inc(A); }
void dcra() { _dec(A); }
void mvia() { A = _mem[PC++]; }
void cmc() { flags.C = !flags.C; }
void movbb() {}
void movbc() { B = C; }
void movbd() { B = D; }
void movbe() { B = E; }
void movbh() { B = H; }
void movbl() { B = L; }
void movbm() { B = _mem[HL]; }
void movba() { B = A; }
void movcb() { C = B; }
void movcc() {}
void movcd() { C = D; }
void movce() { C = E; }
void movch() { C = H; }
void movcl() { C = L; }
void movcm() { C = _mem[HL]; }
void movca() { C = A; }
void movdb() { D = B; }
void movdc() { D = C; }
void movdd() {}
void movde() { D = E; }
void movdh() { D = H; }
void movdl() { D = L; }
void movdm() { D = _mem[HL]; }
void movda() { D = A; }
void moveb() { E = B; }
void movec() { E = C; }
void moved() { E = D; }
void movee() {}
void moveh() { E = H; }
void movel() { E = L; }
void movem() { E = _mem[HL]; }
void movea() { E = A; }
void movhb() { H = B; }
void movhc() { H = C; }
void movhd() { H = D; }
void movhe() { H = E; }
void movhh() {}
void movhl() { H = L; }
void movhm() { H = _mem[HL]; }
void movha() { H = A; }
void movlb() { L = B; }
void movlc() { L = C; }
void movld() { L = D; }
void movle() { L = E; }
void movlh() { L = H; }
void movll() {}
void movlm() { L = _mem[HL]; }
void movla() { L = A; }
void movmb() { _mem[HL] = B; }
void movmc() { _mem[HL] = C; }
void movmd() { _mem[HL] = D; }
void movme() { _mem[HL] = E; }
void movmh() { _mem[HL] = H; }
void movml() { _mem[HL] = L; }
void hlt() { _halted = true; PC--; }
void movma() { _mem[HL] = A; }
inline void dadsp() { _dad(SP); }
inline void lda() { A = _mem[_rw(PC)]; PC += 2; }
inline void dcxsp() { SP--; }
inline void inra() { _inc(A); }
inline void dcra() { _dec(A); }
inline void mvia() { A = _mem[PC++]; }
inline void cmc() { flags.C = !flags.C; }
inline void movbb() {}
inline void movbc() { B = C; }
inline void movbd() { B = D; }
inline void movbe() { B = E; }
inline void movbh() { B = H; }
inline void movbl() { B = L; }
inline void movbm() { B = _mem[HL]; }
inline void movba() { B = A; }
inline void movcb() { C = B; }
inline void movcc() {}
inline void movcd() { C = D; }
inline void movce() { C = E; }
inline void movch() { C = H; }
inline void movcl() { C = L; }
inline void movcm() { C = _mem[HL]; }
inline void movca() { C = A; }
inline void movdb() { D = B; }
inline void movdc() { D = C; }
inline void movdd() {}
inline void movde() { D = E; }
inline void movdh() { D = H; }
inline void movdl() { D = L; }
inline void movdm() { D = _mem[HL]; }
inline void movda() { D = A; }
inline void moveb() { E = B; }
inline void movec() { E = C; }
inline void moved() { E = D; }
inline void movee() {}
inline void moveh() { E = H; }
inline void movel() { E = L; }
inline void movem() { E = _mem[HL]; }
inline void movea() { E = A; }
inline void movhb() { H = B; }
inline void movhc() { H = C; }
inline void movhd() { H = D; }
inline void movhe() { H = E; }
inline void movhh() {}
inline void movhl() { H = L; }
inline void movhm() { H = _mem[HL]; }
inline void movha() { H = A; }
inline void movlb() { L = B; }
inline void movlc() { L = C; }
inline void movld() { L = D; }
inline void movle() { L = E; }
inline void movlh() { L = H; }
inline void movll() {}
inline void movlm() { L = _mem[HL]; }
inline void movla() { L = A; }
inline void movmb() { _mem[HL] = B; }
inline void movmc() { _mem[HL] = C; }
inline void movmd() { _mem[HL] = D; }
inline void movme() { _mem[HL] = E; }
inline void movmh() { _mem[HL] = H; }
inline void movml() { _mem[HL] = L; }
inline void hlt() { _halted = true; PC--; }
inline void movma() { _mem[HL] = A; }
void movab() { A = B; }
void movac() { A = C; }
void movad() { A = D; }
void movae() { A = E; }
void movah() { A = H; }
void moval() { A = L; }
void movam() { A = _mem[HL]; }
void movaa() {}
inline void movab() { A = B; }
inline void movac() { A = C; }
inline void movad() { A = D; }
inline void movae() { A = E; }
inline void movah() { A = H; }
inline void moval() { A = L; }
inline void movam() { A = _mem[HL]; }
inline void movaa() {}
inline void _add(uint8_t x) {
uint16_t w = A + x;
@ -251,14 +251,14 @@ private:
flags.C = w > 0xff;
}
void addb() { _add(B); }
void addc() { _add(C); }
void addd() { _add(D); }
void adde() { _add(E); }
void addh() { _add(H); }
void addl() { _add(L); }
void addm() { _add(_mem[HL]); }
void adda() { _add(A); }
inline void addb() { _add(B); }
inline void addc() { _add(C); }
inline void addd() { _add(D); }
inline void adde() { _add(E); }
inline void addh() { _add(H); }
inline void addl() { _add(L); }
inline void addm() { _add(_mem[HL]); }
inline void adda() { _add(A); }
inline void _adc(uint8_t x) {
uint16_t w = A + x + flags.C;
@ -268,14 +268,14 @@ private:
flags.C = w > 0xff;
}
void adcb() { _adc(B); }
void adcc() { _adc(C); }
void adcd() { _adc(D); }
void adce() { _adc(E); }
void adch() { _adc(H); }
void adcl() { _adc(L); }
void adcm() { _adc(_mem[HL]); }
void adca() { _adc(A); }
inline void adcb() { _adc(B); }
inline void adcc() { _adc(C); }
inline void adcd() { _adc(D); }
inline void adce() { _adc(E); }
inline void adch() { _adc(H); }
inline void adcl() { _adc(L); }
inline void adcm() { _adc(_mem[HL]); }
inline void adca() { _adc(A); }
inline void _sub(uint8_t x) {
uint16_t w = A - x;
@ -285,14 +285,14 @@ private:
flags.C = w > 0xff;
}
void subb() { _sub(B); }
void subc() { _sub(C); }
void subd() { _sub(D); }
void sube() { _sub(E); }
void subh() { _sub(H); }
void subl() { _sub(L); }
void subm() { _sub(_mem[HL]); }
void suba() { _sub(A); }
inline void subb() { _sub(B); }
inline void subc() { _sub(C); }
inline void subd() { _sub(D); }
inline void sube() { _sub(E); }
inline void subh() { _sub(H); }
inline void subl() { _sub(L); }
inline void subm() { _sub(_mem[HL]); }
inline void suba() { _sub(A); }
inline void _sbc(uint8_t x) {
uint16_t w = A - x - flags.C;
@ -302,14 +302,14 @@ private:
flags.C = w > 0xff;
}
void sbbb() { _sbc(B); }
void sbbc() { _sbc(C); }
void sbbd() { _sbc(D); }
void sbbe() { _sbc(E); }
void sbbh() { _sbc(H); }
void sbbl() { _sbc(L); }
void sbbm() { _sbc(_mem[HL]); }
void sbba() { _sbc(A); }
inline void sbbb() { _sbc(B); }
inline void sbbc() { _sbc(C); }
inline void sbbd() { _sbc(D); }
inline void sbbe() { _sbc(E); }
inline void sbbh() { _sbc(H); }
inline void sbbl() { _sbc(L); }
inline void sbbm() { _sbc(_mem[HL]); }
inline void sbba() { _sbc(A); }
inline void _and(uint8_t b) {
A = A & b;
@ -318,14 +318,14 @@ private:
flags.H = 1;
}
void anab() { _and(B); }
void anac() { _and(C); }
void anad() { _and(D); }
void anae() { _and(E); }
void anah() { _and(H); }
void anal() { _and(L); }
void anam() { _and(_mem[HL]); }
void anaa() { _and(A); }
inline void anab() { _and(B); }
inline void anac() { _and(C); }
inline void anad() { _and(D); }
inline void anae() { _and(E); }
inline void anah() { _and(H); }
inline void anal() { _and(L); }
inline void anam() { _and(_mem[HL]); }
inline void anaa() { _and(A); }
inline void _xor(uint8_t b) {
A = A ^ b;
@ -333,14 +333,14 @@ private:
flags.C = flags.H = 0;
}
void xrab() { _xor(B); }
void xrac() { _xor(C); }
void xrad() { _xor(D); }
void xrae() { _xor(E); }
void xrah() { _xor(H); }
void xral() { _xor(L); }
void xram() { _xor(_mem[HL]); }
void xraa() { _xor(A); }
inline void xrab() { _xor(B); }
inline void xrac() { _xor(C); }
inline void xrad() { _xor(D); }
inline void xrae() { _xor(E); }
inline void xrah() { _xor(H); }
inline void xral() { _xor(L); }
inline void xram() { _xor(_mem[HL]); }
inline void xraa() { _xor(A); }
inline void _or(uint8_t b) {
A = A | b;
@ -348,14 +348,14 @@ private:
flags.C = flags.H = 0;
}
void orab() { _or(B); }
void orac() { _or(C); }
void orad() { _or(D); }
void orae() { _or(E); }
void orah() { _or(H); }
void oral() { _or(L); }
void oram() { _or(_mem[HL]); }
void oraa() { _or(A); }
inline void orab() { _or(B); }
inline void orac() { _or(C); }
inline void orad() { _or(D); }
inline void orae() { _or(E); }
inline void orah() { _or(H); }
inline void oral() { _or(L); }
inline void oram() { _or(_mem[HL]); }
inline void oraa() { _or(A); }
inline void _cmp(uint8_t b) {
uint16_t w = A - b;
@ -363,14 +363,14 @@ private:
flags.C = w > 0xff;
}
void cmpb() { _cmp(B); }
void cmpc() { _cmp(C); }
void cmpd() { _cmp(D); }
void cmpe() { _cmp(E); }
void cmph() { _cmp(H); }
void cmpl() { _cmp(L); }
void cmpm() { _cmp(_mem[HL]); }
void cmpa() { _cmp(A); }
inline void cmpb() { _cmp(B); }
inline void cmpc() { _cmp(C); }
inline void cmpd() { _cmp(D); }
inline void cmpe() { _cmp(E); }
inline void cmph() { _cmp(H); }
inline void cmpl() { _cmp(L); }
inline void cmpm() { _cmp(_mem[HL]); }
inline void cmpa() { _cmp(A); }
inline uint8_t _popb() { return _mem[SP++]; }
inline void _pushb(uint8_t b) { _mem[--SP] = b; }
@ -381,70 +381,70 @@ private:
inline void _ret(uint8_t c) { if (c) ret(); }
inline void _call(uint8_t c) { if (c) call(); else PC += 2; }
void rnz() { _ret(!flags.Z); }
void popb() { BC = _pop(); }
void jnz() { _jmp(!flags.Z); }
void jmp() { PC = _rw(PC); }
void cnz() { _call(!flags.Z); }
void pushb() { _push(BC); }
void adi() { _add(_mem[PC++]); }
void rst0() { _push(PC); PC = 0x00; }
void rz() { _ret(flags.Z); }
void ret() { PC = _pop(); }
void jz() { _jmp(flags.Z); }
inline void rnz() { _ret(!flags.Z); }
inline void popb() { BC = _pop(); }
inline void jnz() { _jmp(!flags.Z); }
inline void jmp() { PC = _rw(PC); }
inline void cnz() { _call(!flags.Z); }
inline void pushb() { _push(BC); }
inline void adi() { _add(_mem[PC++]); }
inline void rst0() { _push(PC); PC = 0x00; }
inline void rz() { _ret(flags.Z); }
inline void ret() { PC = _pop(); }
inline void jz() { _jmp(flags.Z); }
void cz() { _call(flags.Z); }
void call() { _push(PC+2); PC = _rw(PC); }
void aci() { _adc(_mem[PC++]); }
void rst1() { _push(PC); PC = 0x08; }
void rnc() { _ret(!flags.C); }
void popd() { DE = _pop(); }
void jnc() { _jmp(!flags.C); }
void out() { _ports->out(_mem[PC++], A, this); }
void cnc() { _call(!flags.C); }
void pushd() { _push(DE); }
void sui() { _sub(_mem[PC++]); }
void rst2() { _push(PC); PC = 0x10; }
void rc() { _ret(flags.C); }
inline void cz() { _call(flags.Z); }
inline void call() { _push(PC+2); PC = _rw(PC); }
inline void aci() { _adc(_mem[PC++]); }
inline void rst1() { _push(PC); PC = 0x08; }
inline void rnc() { _ret(!flags.C); }
inline void popd() { DE = _pop(); }
inline void jnc() { _jmp(!flags.C); }
inline void out() { _ports->out(_mem[PC++], A, this); }
inline void cnc() { _call(!flags.C); }
inline void pushd() { _push(DE); }
inline void sui() { _sub(_mem[PC++]); }
inline void rst2() { _push(PC); PC = 0x10; }
inline void rc() { _ret(flags.C); }
void jc() { _jmp(flags.C); }
void in() { A = _ports->in(_mem[PC++], this); }
void cc() { _call(flags.C); }
inline void jc() { _jmp(flags.C); }
inline void in() { A = _ports->in(_mem[PC++], this); }
inline void cc() { _call(flags.C); }
void sbi() { _sbc(_mem[PC++]); }
void rst3() { _push(PC); PC = 0x18; }
void rpo() { _ret(!flags.P); }
void poph() { HL = _pop(); }
void jpo() { _jmp(!flags.P); }
void xthl() { uint16_t w = _pop(); _push(HL); HL = w; }
void cpo() { _call(!flags.P); }
void pushh() { _push(HL); }
void ani() { _and(_mem[PC++]); }
void rst4() { _push(PC); PC = 0x20; }
void rpe() { _ret(flags.P); }
void pchl() { PC = HL; }
void jpe() { _jmp(flags.P); }
void xchg() { uint16_t w = DE; DE = HL; HL = w; }
void cpe() { _call(flags.P); }
inline void sbi() { _sbc(_mem[PC++]); }
inline void rst3() { _push(PC); PC = 0x18; }
inline void rpo() { _ret(!flags.P); }
inline void poph() { HL = _pop(); }
inline void jpo() { _jmp(!flags.P); }
inline void xthl() { uint16_t w = _pop(); _push(HL); HL = w; }
inline void cpo() { _call(!flags.P); }
inline void pushh() { _push(HL); }
inline void ani() { _and(_mem[PC++]); }
inline void rst4() { _push(PC); PC = 0x20; }
inline void rpe() { _ret(flags.P); }
inline void pchl() { PC = HL; }
inline void jpe() { _jmp(flags.P); }
inline void xchg() { uint16_t w = DE; DE = HL; HL = w; }
inline void cpe() { _call(flags.P); }
void xri() { _xor(_mem[PC++]); }
void rst5() { _push(PC); PC = 0x28; }
void rp() { _ret(!flags.S); }
void pop() { _sr(_popb()); A = _popb(); }
void jp() { _jmp(!flags.S); }
void di() { flags.I = 0; }
void cp() { _call(!flags.S); }
void push() { _pushb(A); _pushb(SR); }
void ori() { _or(_mem[PC++]); }
void rst6() { _push(PC); PC = 0x30; }
void rm() { _ret(flags.S); }
void sphl() { SP = HL; }
void jm() { _jmp(flags.S); }
void ei();
void cm() { _call(flags.S); }
inline void xri() { _xor(_mem[PC++]); }
inline void rst5() { _push(PC); PC = 0x28; }
inline void rp() { _ret(!flags.S); }
inline void pop() { _sr(_popb()); A = _popb(); }
inline void jp() { _jmp(!flags.S); }
inline void di() { flags.I = 0; }
inline void cp() { _call(!flags.S); }
inline void push() { _pushb(A); _pushb(SR); }
inline void ori() { _or(_mem[PC++]); }
inline void rst6() { _push(PC); PC = 0x30; }
inline void rm() { _ret(flags.S); }
inline void sphl() { SP = HL; }
inline void jm() { _jmp(flags.S); }
inline void ei() { flags.I = 1; if (_irq_pending) raise(_irq_pending); }
inline void cm() { _call(flags.S); }
void cpi() { _cmp(_mem[PC++]); }
void rst7() { _push(PC); PC = 0x38; }
inline void cpi() { _cmp(_mem[PC++]); }
inline void rst7() { _push(PC); PC = 0x38; }
};
#endif