enum {
	L_N=0,
	L_SKIP,
	/* Grouped ones using MOD/RM */
	L_MODRM,L_POPwRM,L_POPdRM,
	
	L_Ib,L_Iw,L_Id,
	L_Ibx,L_Iwx,L_Idx,				//Sign extend
	L_Ifw,L_Ifd,
	L_OP,

	L_REGb,L_REGw,L_REGd,
	L_REGbIb,L_REGwIw,L_REGdId,
	L_POPw,L_POPd,
	L_POPfw,L_POPfd,
	L_SEG,

	L_FLG,L_INTO,

	L_VAL,
	L_PRESEG,
	L_DOUBLE,
	L_PREOP,L_PREADD,L_PREREP,L_PREREPNE,
	L_STRING,

/* Direct ones */
	D_IRETw,D_IRETd,
	D_PUSHAw,D_PUSHAd,
	D_POPAw,D_POPAd,
	D_POPSEGw,D_POPSEGd,
	D_DAA,D_DAS,
	D_AAA,D_AAS,
	D_CBW,D_CWDE,
	D_CWD,D_CDQ,
	D_SETALC,
	D_XLAT,
	D_CLI,D_STI,D_STC,D_CLC,D_CMC,D_CLD,D_STD,
	D_NOP,D_WAIT,
	D_ENTERw,D_ENTERd,
	D_LEAVEw,D_LEAVEd,
	
	D_RETFw,D_RETFd,
	D_RETFwIw,D_RETFdIw,
	D_CPUID,
	D_HLT,D_CLTS,
	L_ERROR,
};


enum {
	O_N=t_LASTFLAG,
	O_COND,
	O_XCHG_AX,O_XCHG_EAX,
	O_IMULRw,O_IMULRd,
	O_BOUNDw,O_BOUNDd,
	O_CALLNw,O_CALLNd,
	O_CALLFw,O_CALLFd,
	O_JMPFw,O_JMPFd,

	O_OPAL,O_ALOP,
	O_OPAX,O_AXOP,
	O_OPEAX,O_EAXOP,
	O_INT,
	O_SEGDS,O_SEGES,O_SEGFS,O_SEGGS,O_SEGSS,
	O_LOOP,O_LOOPZ,O_LOOPNZ,O_JCXZ,
	O_INb,O_INw,O_INd,
	O_OUTb,O_OUTw,O_OUTd,

	O_NOT,O_AAM,O_AAD,
	O_MULb,O_MULw,O_MULd,
	O_IMULb,O_IMULw,O_IMULd,
	O_DIVb,O_DIVw,O_D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,M_EwxIbx,M_EwxIwx,M_EwGwIb,M_EwGwCL,
	M_EdId,M_EdIbx,M_EdGdIb,M_EdGdCL,
	
	M_Efw,M_Efd,
	
	M_Ib,M_Iw,M_Id,


	M_SEG,M_EA,
	M_GRP,
	M_GRP_Ib,M_GRP_CL,M_GRP_1,

	M_POPw,M_POPd,
};

struct OpCode {
	Bit8u load,op,save,extra;
};

struct FullData {
	Bitu entry;
	EAPoint opcode_start;
	Bitu rm;
	EAPoint rm_eaa;
	Bitu rm_off;
	Bitu rm_eai;
	Bitu rm_index;
	Bitu rm_mod;
	OpCode code;
	union {	
		Bit8u b;Bit8s bs;
		Bit16u w;Bit16s ws;
		Bit32u d;Bit32s ds;
	} op1,op2,imm;
	Bitu new_flags;
	struct {
		EAPoint base;
	} seg;
	Bitu cond;
	bool repz;
	Bitu prefix;
	Bitu start_prefix;
	Bitu start_entry;
};


#define PREFIX_NONE		0x0
#define PREFIX_SEG		0x1
#define PREFIX_ADDR		0x2
#define PREFIX_REP		0x4

