summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/i86/modrm.h
blob: 5919ebf230a3e5823332b0b183a01d8b94937377 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
static struct
{
	struct
	{
		WREGS w[256];
		BREGS b[256];
	} reg;
	struct
	{
		WREGS w[256];
		BREGS b[256];
	} RM;
} Mod_RM;

#define RegWord(ModRM) cpustate->regs.w[Mod_RM.reg.w[ModRM]]
#define RegByte(ModRM) cpustate->regs.b[Mod_RM.reg.b[ModRM]]

#define GetRMWord(ModRM) \
	((ModRM) >= 0xc0 ? cpustate->regs.w[Mod_RM.RM.w[ModRM]] : ( (*GetEA[ModRM])(cpustate), ReadWord( cpustate->ea ) ))

#define PutbackRMWord(ModRM,val) \
{ \
	if (ModRM >= 0xc0) cpustate->regs.w[Mod_RM.RM.w[ModRM]]=val; \
    else WriteWord(cpustate->ea,val); \
}

#define GetnextRMWord ReadWord(cpustate->ea+2)

#define GetRMWordOffset(offs) \
		ReadWord(cpustate->ea-cpustate->eo+(UINT16)(cpustate->eo+offs))

#define GetRMByteOffset(offs) \
		ReadByte(cpustate->ea-cpustate->eo+(UINT16)(cpustate->eo+offs))

#define PutRMWord(ModRM,val)				\
{											\
	if (ModRM >= 0xc0)						\
		cpustate->regs.w[Mod_RM.RM.w[ModRM]]=val;	\
	else {									\
		(*GetEA[ModRM])(cpustate);					\
		WriteWord( cpustate->ea ,val);				\
	}										\
}

#define PutRMWordOffset(offs, val) \
		WriteWord( cpustate->ea-cpustate->eo+(UINT16)(cpustate->eo+offs), val)

#define PutRMByteOffset(offs, val) \
		WriteByte( cpustate->ea-cpustate->eo+(UINT16)(cpustate->eo+offs), val)

#define PutImmRMWord(ModRM) 				\
{											\
	WORD val;								\
	if (ModRM >= 0xc0)						\
		FETCHWORD(cpustate->regs.w[Mod_RM.RM.w[ModRM]]) \
	else {									\
		(*GetEA[ModRM])(cpustate);					\
		FETCHWORD(val)						\
		WriteWord( cpustate->ea , val);				\
	}										\
}

#define GetRMByte(ModRM) \
	((ModRM) >= 0xc0 ? cpustate->regs.b[Mod_RM.RM.b[ModRM]] : ReadByte( (*GetEA[ModRM])(cpustate) ))

#define PutRMByte(ModRM,val)				\
{											\
	if (ModRM >= 0xc0)						\
		cpustate->regs.b[Mod_RM.RM.b[ModRM]]=val;	\
	else									\
		WriteByte( (*GetEA[ModRM])(cpustate) ,val); \
}

#define PutImmRMByte(ModRM) 				\
{											\
	if (ModRM >= 0xc0)						\
		cpustate->regs.b[Mod_RM.RM.b[ModRM]]=FETCH; \
	else {									\
		(*GetEA[ModRM])(cpustate);					\
		WriteByte( cpustate->ea , FETCH );			\
	}										\
}

#define PutbackRMByte(ModRM,val)			\
{											\
	if (ModRM >= 0xc0)						\
		cpustate->regs.b[Mod_RM.RM.b[ModRM]]=val;	\
	else									\
		WriteByte(cpustate->ea,val);					\
}

#define DEF_br8(dst,src)					\
	unsigned ModRM = FETCHOP;				\
	unsigned src = RegByte(ModRM);			\
    unsigned dst = GetRMByte(ModRM)

#define DEF_wr16(dst,src)					\
	unsigned ModRM = FETCHOP;				\
	unsigned src = RegWord(ModRM);			\
    unsigned dst = GetRMWord(ModRM)

#define DEF_r8b(dst,src)					\
	unsigned ModRM = FETCHOP;				\
	unsigned dst = RegByte(ModRM);			\
    unsigned src = GetRMByte(ModRM)

#define DEF_r16w(dst,src)					\
	unsigned ModRM = FETCHOP;				\
	unsigned dst = RegWord(ModRM);			\
    unsigned src = GetRMWord(ModRM)

#define DEF_ald8(dst,src)					\
	unsigned src = FETCHOP; 				\
	unsigned dst = cpustate->regs.b[AL]

#define DEF_axd16(dst,src)					\
	unsigned src = FETCHOP; 				\
	unsigned dst = cpustate->regs.w[AX];			\
    src += (FETCH << 8)