//					DISASM.H

#ifndef disasmh
#define disasmh

struct asmlist
{ struct asmlist *next,*last;
  unsigned char opcode;
  unsigned long addr;
  unsigned int bytelength;
  unsigned char *data;
  unsigned char arg1type;
  unsigned long arg1;
  unsigned char arg2type;
  unsigned long arg2;
  unsigned long displacement;
  unsigned char segprefix,sib;
  unsigned long thirdarg;
};

class disasm
{ public:
	 BOOL mode32;

  private:
	 struct asmlist *disassembly;
	 struct asmlist *lastasm;
	 unsigned char prefix;
	 unsigned char lastsib;
	 BOOL operandprefix;
	 BOOL addressprefix;
	 unsigned int codeplus;
	 int speed,barct,stepsize;
	 unsigned char *sarg;
	 unsigned long instct;

  public:
	 disasm();
	 ~disasm();
	 void decode(void);
    void dumpasm(void);
	 struct asmlist *getdisassembly(void);
    unsigned long getinstct(void);
	 void hintdata(unsigned long ip,unsigned char op);

  private:
    void decoderefs(void);
	 void decodeblock(struct codedata *block,unsigned long ip);
	 void decoderest(struct codedata *block);
	 void decodepossibles(struct codedata *block);
	 unsigned char toasm(unsigned long ip,unsigned long bsize,
								unsigned long vsize,unsigned char *data);
	 void addtoasm(unsigned long address,unsigned char op,unsigned int len,
						unsigned char *data,unsigned char arg1type,unsigned long arg1,
						unsigned char arg2type,unsigned long arg2,unsigned long disp);
	 void PrintArgs(unsigned char arg1type,unsigned long arg1,
						unsigned char arg2type,unsigned long arg2,unsigned long disp);
	 void PrintArg(unsigned char argtype,unsigned long arg,unsigned long disp);
	 unsigned char modrmbyte(unsigned char *byte,unsigned char *type,unsigned long *value,
						unsigned long *displacement);
	 unsigned char modrm16byte(unsigned char *byte,unsigned char *type,unsigned long *value,
						unsigned long *displacement);
	 unsigned char modrm16_8byte(unsigned char *byte,unsigned char *type,unsigned long *value,
						unsigned long *displacement);
	 unsigned char modrm8byte(unsigned char *byte,unsigned char *type,unsigned long *value,
						unsigned long *displacement);
	 void PrintSib(void);
};

#endif