2016-01-27 11:31:39 +00:00
|
|
|
//NEC V30MZ
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Processor {
|
|
|
|
|
|
|
|
struct V30MZ {
|
2016-02-04 10:29:08 +00:00
|
|
|
using Size = uint;
|
2016-02-03 10:24:58 +00:00
|
|
|
enum : uint { Byte = 1, Word = 2, Long = 4 };
|
2016-01-31 07:59:44 +00:00
|
|
|
|
2016-01-28 11:39:49 +00:00
|
|
|
virtual auto wait(uint clocks = 1) -> void = 0;
|
|
|
|
virtual auto read(uint20 addr) -> uint8 = 0;
|
|
|
|
virtual auto write(uint20 addr, uint8 data) -> void = 0;
|
2016-01-30 06:40:35 +00:00
|
|
|
virtual auto in(uint16 port) -> uint8 = 0;
|
|
|
|
virtual auto out(uint16 port, uint8 data) -> void = 0;
|
2016-01-27 11:31:39 +00:00
|
|
|
|
|
|
|
auto exec() -> void;
|
2016-02-04 10:29:08 +00:00
|
|
|
auto instruction() -> void;
|
|
|
|
auto interrupt(uint8 vector) -> void;
|
2016-01-27 11:31:39 +00:00
|
|
|
auto power() -> void;
|
|
|
|
|
2016-01-30 06:40:35 +00:00
|
|
|
//registers.cpp
|
2016-02-03 10:24:58 +00:00
|
|
|
auto segment(uint16) -> uint16;
|
|
|
|
|
|
|
|
auto getAcc(Size) -> uint32;
|
|
|
|
auto setAcc(Size, uint32) -> void;
|
2016-01-31 07:59:44 +00:00
|
|
|
|
2016-02-02 10:51:17 +00:00
|
|
|
//modrm.cpp
|
2016-02-04 10:29:08 +00:00
|
|
|
auto modRM() -> void;
|
2016-02-02 10:51:17 +00:00
|
|
|
|
2016-02-04 10:29:08 +00:00
|
|
|
auto getMem(Size, uint offset = 0) -> uint16;
|
|
|
|
auto setMem(Size, uint16) -> void;
|
2016-02-02 10:51:17 +00:00
|
|
|
|
2016-02-04 10:29:08 +00:00
|
|
|
auto getReg(Size) -> uint16;
|
|
|
|
auto setReg(Size, uint16) -> void;
|
|
|
|
|
|
|
|
auto getSeg() -> uint16;
|
|
|
|
auto setSeg(uint16) -> void;
|
2016-01-30 06:40:35 +00:00
|
|
|
|
2016-01-28 11:39:49 +00:00
|
|
|
//memory.cpp
|
2016-02-03 10:24:58 +00:00
|
|
|
auto read(Size, uint16, uint16) -> uint32;
|
2016-01-31 07:59:44 +00:00
|
|
|
auto write(Size, uint16, uint16, uint16) -> void;
|
|
|
|
|
2016-02-03 10:24:58 +00:00
|
|
|
auto in(Size, uint16) -> uint16;
|
|
|
|
auto out(Size, uint16, uint16) -> void;
|
|
|
|
|
2016-02-02 10:51:17 +00:00
|
|
|
auto fetch(Size = Byte) -> uint16;
|
|
|
|
auto pop() -> uint16;
|
|
|
|
auto push(uint16) -> void;
|
2016-01-30 06:40:35 +00:00
|
|
|
|
|
|
|
//algorithms.cpp
|
2016-02-04 10:29:08 +00:00
|
|
|
auto parity(uint8) const -> bool;
|
2016-02-02 10:51:17 +00:00
|
|
|
auto alAdc(Size, uint16, uint16) -> uint16;
|
|
|
|
auto alAdd(Size, uint16, uint16) -> uint16;
|
2016-01-31 07:59:44 +00:00
|
|
|
auto alAnd(Size, uint16, uint16) -> uint16;
|
2016-02-03 10:24:58 +00:00
|
|
|
auto alDec(Size, uint16 ) -> uint16;
|
|
|
|
auto alDiv(Size, uint32, uint32) -> uint32;
|
|
|
|
auto alDivi(Size, int32, int32) -> uint32;
|
|
|
|
auto alInc(Size, uint16 ) -> uint16;
|
|
|
|
auto alMul(Size, uint16, uint16) -> uint32;
|
|
|
|
auto alMuli(Size, int16, int16) -> uint32;
|
|
|
|
auto alNeg(Size, uint16 ) -> uint16;
|
|
|
|
auto alNot(Size, uint16 ) -> uint16;
|
2016-02-02 10:51:17 +00:00
|
|
|
auto alOr (Size, uint16, uint16) -> uint16;
|
|
|
|
auto alRcl(Size, uint16, uint5 ) -> uint16;
|
|
|
|
auto alRcr(Size, uint16, uint5 ) -> uint16;
|
|
|
|
auto alRol(Size, uint16, uint4 ) -> uint16;
|
|
|
|
auto alRor(Size, uint16, uint4 ) -> uint16;
|
|
|
|
auto alSal(Size, uint16, uint5 ) -> uint16;
|
|
|
|
auto alSar(Size, uint16, uint5 ) -> uint16;
|
|
|
|
auto alSbb(Size, uint16, uint16) -> uint16;
|
|
|
|
auto alSub(Size, uint16, uint16) -> uint16;
|
|
|
|
auto alShl(Size, uint16, uint5 ) -> uint16;
|
|
|
|
auto alShr(Size, uint16, uint5 ) -> uint16;
|
|
|
|
auto alXor(Size, uint16, uint16) -> uint16;
|
2016-01-28 11:39:49 +00:00
|
|
|
|
2016-02-04 10:29:08 +00:00
|
|
|
//instructions-adjust.cpp
|
|
|
|
auto opDecimalAdjust(bool);
|
|
|
|
auto opAsciiAdjust(bool);
|
|
|
|
auto opAdjustAfterMultiply();
|
|
|
|
auto opAdjustAfterDivide();
|
|
|
|
|
|
|
|
//instructions-alu.cpp
|
2016-02-02 10:51:17 +00:00
|
|
|
auto opAddMemReg(Size);
|
|
|
|
auto opAddRegMem(Size);
|
|
|
|
auto opAddAccImm(Size);
|
|
|
|
auto opOrMemReg(Size);
|
|
|
|
auto opOrRegMem(Size);
|
|
|
|
auto opOrAccImm(Size);
|
|
|
|
auto opAdcMemReg(Size);
|
|
|
|
auto opAdcRegMem(Size);
|
|
|
|
auto opAdcAccImm(Size);
|
|
|
|
auto opSbbMemReg(Size);
|
|
|
|
auto opSbbRegMem(Size);
|
|
|
|
auto opSbbAccImm(Size);
|
|
|
|
auto opAndMemReg(Size);
|
|
|
|
auto opAndRegMem(Size);
|
|
|
|
auto opAndAccImm(Size);
|
|
|
|
auto opSubMemReg(Size);
|
|
|
|
auto opSubRegMem(Size);
|
|
|
|
auto opSubAccImm(Size);
|
|
|
|
auto opXorMemReg(Size);
|
|
|
|
auto opXorRegMem(Size);
|
|
|
|
auto opXorAccImm(Size);
|
|
|
|
auto opCmpMemReg(Size);
|
|
|
|
auto opCmpRegMem(Size);
|
|
|
|
auto opCmpAccImm(Size);
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opTestMemReg(Size);
|
|
|
|
auto opTestAcc(Size);
|
|
|
|
auto opMultiplySignedRegMemImm(Size);
|
2016-02-02 10:51:17 +00:00
|
|
|
auto opIncReg(uint16&);
|
|
|
|
auto opDecReg(uint16&);
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opSignExtendByte();
|
|
|
|
auto opSignExtendWord();
|
|
|
|
|
|
|
|
//instructions-exec.cpp
|
|
|
|
auto opLoop();
|
|
|
|
auto opLoopWhile(bool);
|
|
|
|
auto opJumpShort();
|
|
|
|
auto opJumpIf(bool);
|
|
|
|
auto opJumpNear();
|
|
|
|
auto opJumpFar();
|
|
|
|
auto opCallNear();
|
|
|
|
auto opCallFar();
|
|
|
|
auto opReturn();
|
|
|
|
auto opReturnImm();
|
|
|
|
auto opReturnFar();
|
|
|
|
auto opReturnFarImm();
|
|
|
|
auto opReturnInt();
|
|
|
|
auto opInt3();
|
|
|
|
auto opIntImm();
|
|
|
|
auto opInto();
|
|
|
|
auto opEnter();
|
|
|
|
auto opLeave();
|
2016-02-02 10:51:17 +00:00
|
|
|
auto opPushReg(uint16&);
|
|
|
|
auto opPopReg(uint16&);
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opPushFlags();
|
|
|
|
auto opPopFlags();
|
2016-02-03 10:24:58 +00:00
|
|
|
auto opPushAll();
|
|
|
|
auto opPopAll();
|
|
|
|
auto opPushImm(Size);
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opPopMem();
|
|
|
|
|
|
|
|
//instructions-flag.cpp
|
2016-02-03 10:24:58 +00:00
|
|
|
auto opStoreFlagsAcc();
|
|
|
|
auto opLoadAccFlags();
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opComplementCarry();
|
|
|
|
auto opClearFlag(bool&);
|
|
|
|
auto opSetFlag(bool&);
|
|
|
|
|
|
|
|
//instructions-group.cpp
|
2016-02-02 10:51:17 +00:00
|
|
|
auto opGroup1MemImm(Size, bool);
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opGroup2MemImm(Size, maybe<uint8> = {});
|
|
|
|
auto opGroup3MemImm(Size);
|
|
|
|
auto opGroup4MemImm(Size);
|
|
|
|
|
|
|
|
//instructions-misc.cpp
|
|
|
|
auto opSegment(uint16);
|
|
|
|
auto opRepeat(bool);
|
|
|
|
auto opLock();
|
|
|
|
auto opWait();
|
|
|
|
auto opHalt();
|
|
|
|
auto opNop();
|
|
|
|
auto opIn(Size);
|
|
|
|
auto opOut(Size);
|
|
|
|
auto opInDX(Size);
|
|
|
|
auto opOutDX(Size);
|
|
|
|
auto opTranslate();
|
|
|
|
auto opBound();
|
|
|
|
|
|
|
|
//instructions-move.cpp
|
2016-02-02 10:51:17 +00:00
|
|
|
auto opMoveMemReg(Size);
|
|
|
|
auto opMoveRegMem(Size);
|
2016-02-03 10:24:58 +00:00
|
|
|
auto opMoveMemSeg();
|
2016-02-02 10:51:17 +00:00
|
|
|
auto opMoveSegMem();
|
|
|
|
auto opMoveAccMem(Size);
|
|
|
|
auto opMoveMemAcc(Size);
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opMoveRegImm(uint8&);
|
|
|
|
auto opMoveRegImm(uint16&);
|
|
|
|
auto opMoveMemImm(Size);
|
|
|
|
auto opExchange(uint16&, uint16&);
|
|
|
|
auto opExchangeMemReg(Size);
|
|
|
|
auto opLoadEffectiveAddressRegMem();
|
|
|
|
auto opLoadSegmentMem(uint16&);
|
|
|
|
|
|
|
|
//instructions-string.cpp
|
2016-02-03 10:24:58 +00:00
|
|
|
auto opInString(Size);
|
|
|
|
auto opOutString(Size);
|
2016-01-31 07:59:44 +00:00
|
|
|
auto opMoveString(Size);
|
2016-02-03 10:07:50 +00:00
|
|
|
auto opCompareString(Size);
|
2016-02-02 10:51:17 +00:00
|
|
|
auto opStoreString(Size);
|
2016-02-03 10:07:50 +00:00
|
|
|
auto opLoadString(Size);
|
2016-02-04 10:29:08 +00:00
|
|
|
auto opScanString(Size);
|
2016-01-28 11:39:49 +00:00
|
|
|
|
|
|
|
//disassembler.cpp
|
2016-02-02 10:51:17 +00:00
|
|
|
auto disassemble(uint16 cs, uint16 ip, bool registers = true, bool bytes = true) -> string;
|
2016-01-28 11:39:49 +00:00
|
|
|
|
2016-02-04 10:29:08 +00:00
|
|
|
struct State {
|
2016-02-04 21:18:06 +00:00
|
|
|
bool halt; //set to true for hlt instruction; blocks execution until next interrupt
|
|
|
|
bool poll; //set to false to suppress interrupt polling between CPU instructions
|
|
|
|
bool prefix; //set to true for prefix instructions; prevents flushing of Prefix struct
|
2016-02-04 10:29:08 +00:00
|
|
|
} state;
|
2016-01-28 11:39:49 +00:00
|
|
|
|
2016-02-03 10:07:50 +00:00
|
|
|
struct Prefix {
|
2016-02-04 21:18:06 +00:00
|
|
|
maybe<bool> repeat; //repnz, repz
|
|
|
|
maybe<uint16> segment; //cs, es, ss, ds
|
2016-02-03 10:07:50 +00:00
|
|
|
} prefix;
|
|
|
|
|
2016-02-04 10:29:08 +00:00
|
|
|
struct ModRM {
|
|
|
|
uint2 mod;
|
|
|
|
uint3 reg;
|
|
|
|
uint3 mem;
|
2016-02-02 10:51:17 +00:00
|
|
|
|
2016-02-04 10:29:08 +00:00
|
|
|
uint16 segment;
|
2016-02-04 21:18:06 +00:00
|
|
|
uint16 address;
|
2016-02-04 10:29:08 +00:00
|
|
|
} modrm;
|
|
|
|
|
|
|
|
struct Registers {
|
2016-01-30 06:40:35 +00:00
|
|
|
union { uint16 ax; struct { uint8 order_lsb2(al, ah); }; };
|
|
|
|
union { uint16 cx; struct { uint8 order_lsb2(cl, ch); }; };
|
|
|
|
union { uint16 dx; struct { uint8 order_lsb2(dl, dh); }; };
|
2016-02-04 21:18:06 +00:00
|
|
|
union { uint16 bx; struct { uint8 order_lsb2(bl, bh); }; };
|
|
|
|
uint16 sp;
|
|
|
|
uint16 bp;
|
2016-01-27 11:31:39 +00:00
|
|
|
uint16 si;
|
|
|
|
uint16 di;
|
2016-01-28 11:39:49 +00:00
|
|
|
uint16 es;
|
2016-02-04 21:18:06 +00:00
|
|
|
uint16 cs;
|
2016-01-28 11:39:49 +00:00
|
|
|
uint16 ss;
|
2016-02-04 21:18:06 +00:00
|
|
|
uint16 ds;
|
|
|
|
uint16 ip;
|
2016-01-30 06:40:35 +00:00
|
|
|
|
2016-02-04 10:29:08 +00:00
|
|
|
uint8* b[8]{&al, &cl, &dl, &bl, &ah, &ch, &dh, &bh};
|
|
|
|
uint16* w[8]{&ax, &cx, &dx, &bx, &sp, &bp, &si, &di};
|
|
|
|
uint16* s[8]{&es, &cs, &ss, &ds, &es, &cs, &ss, &ds};
|
|
|
|
|
2016-01-28 11:39:49 +00:00
|
|
|
struct Flags {
|
2016-02-02 10:51:17 +00:00
|
|
|
//registers.cpp
|
2016-01-28 11:39:49 +00:00
|
|
|
operator uint16() const;
|
|
|
|
auto operator=(uint16 data);
|
|
|
|
|
|
|
|
bool m; //mode
|
|
|
|
bool v; //overflow
|
|
|
|
bool d; //direction
|
|
|
|
bool i; //interrupt
|
|
|
|
bool b; //break
|
|
|
|
bool s; //sign
|
|
|
|
bool z; //zero
|
|
|
|
bool h; //half-carry
|
|
|
|
bool p; //parity
|
|
|
|
bool c; //carry
|
|
|
|
} f;
|
2016-01-27 11:31:39 +00:00
|
|
|
} r;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|